Cannot make the sprite move #1605
-
Hi, I am trying to build a moving slide for volume. After following the code in https://github.com/Bodmer/TFT_eSPI/blob/master/examples/Sprite/Sprite_scroll_16bit/Sprite_scroll_16bit.ino , I came out with following code. But I found the slide cannot move as the "vol" input change (I checked the value by serial print). May I know what's wrong with my code? void drawSlide(int32_t x, int32_t y, int32_t vol, TFT_eSprite bar, bool flag_refresh = true)
{
uint8_t width = 25;
uint8_t height = 105;
uint8_t vol_max = 100;
uint8_t slide_center_w = 2;
if (flag_refresh)
{
bar.setColorDepth(16);
bar.createSprite(width, height);
}
bar.fillSprite(TFT_BLACK);
bar.fillRect(12, 0, slide_center_w, height, 0x632F);
bar.fillRect(0, vol_max - vol, width, 5, 0x6C7F);
bar.pushSprite(x, y);
} Thanks a lot! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Seems to work for me, here is the test code:
|
Beta Was this translation helpful? Give feedback.
-
The approach depends on whether you want the sprite to persist or be recreated every time the function is called. Sprite creation is fast and automatic deletion recovers the memory. If you want the sprite to persist for the function then you could use static variables so it is only created once and stays in scope for sole use of the function, for example:
|
Beta Was this translation helpful? Give feedback.
Seems to work for me, here is the test code: