problem with TFT_eSprite
-
Hi all
I have a problem with spritesI have some objects that draw some circels, strings or line to the M5core2.
I do that with the following code
x = 230; uint32_t _r = r; // 50 uint32_t _w = _r * 2; uint32_t _h = _r * 2; TFT_eSprite _sprite = new TFT_eSprite(&M5.Lcd); _sprite.createSprite(_w, _h); _sprite.drawCircle(_r, _r, _r, _color); _sprite.drawCircle(_r, _r, _r - 1, _color); _sprite.fillCircle(_r, _r, _r - 2, _colorCircle); _sprite.pushSprite(x - _r + 4, y - _r + 4); _sprite.deleteSprite();
That works fine if x is lower than 230. As soon x is bigger than 230 every pixel that is outside 280 is trunccatet from the circle
Any ideas or is thre a limitation with sprites?
-
You don't show what Y is, or what your screen orientation is set to. If I remember correctly, if any part of a sprite gets pushed offscreen, the sprite will be truncated. So make sure the bounds of the sprite are within the 320 x 240 pixels of the LCD when you push it. The paramaters to pushSprite are the "upper left corner" of where you want the sprite to be placed.
Look through the examples at https://github.com/m5stack/M5Stack/tree/master/examples/Advanced/Display/Sprite to failiarize yourself.
-
When x is larger than 230, the circle is pushed to a position where part of it exceeds the screen width (320 pixels wide), specifically beyond the x value of 280 (since your circle has a diameter of 100 pixels, calculated from _r = 50, and its center is at x - _r + 4).
Sprites are typically clipped when drawn outside the screen area, meaning any part of the sprite that extends beyond the screen boundary will not be displayed.To prevent the sprite from being truncated, you can implement a check to ensure that the sprite's position remains within the screen's boundaries before calling pushSprite.
Here’s an updated version of your code:
// Ensure the sprite stays within the screen's bounds x = (x > 270) ? 270 : x; // Adjust x to stay within the screen width uint32_t _r = r; // 50 uint32_t _w = _r * 2; uint32_t _h = _r * 2; TFT_eSprite _sprite = new TFT_eSprite(&M5.Lcd); _sprite.createSprite(_w, _h); _sprite.drawCircle(_r, _r, _r, _color); _sprite.drawCircle(_r, _r, _r - 1, _color); _sprite.fillCircle(_r, _r, _r - 2, _colorCircle); // Push sprite only within the screen's bounds _sprite.pushSprite(x - _r + 4, y - _r + 4); _sprite.deleteSprite();