Needle animation over static image background #3732
              
                Unanswered
              
          
                  
                    
                      zdravke
                    
                  
                
                  asked this question in
                Q&A - Sprites
              
            Replies: 1 comment
-
| 
         Did this a while ago. Might give some clues  | 
  
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I’m wondering if I’m using sprites in the most efficient way. I have ESP32-WROOM with st7789 1.9inch display and trying to animate smooth vu meter needle over a preloaded vu meter background.
void drawNeedles(float mainAngle, float peakAngle) {
// 1. Draw the background in the area where the needle will move
needleSprite.pushImage(0, 0, 320, HEIGHT, background); // Full background redraw
// 2. Draw the peak needle
float rad = peakAngle * DEG_TO_RAD;
float tipX = needleCenterX - needleLength * cos(rad);
float tipY = needleCenterY - needleLength * sin(rad);
float baseX = needleCenterX + (tipX - needleCenterX) * (needleCenterY - HEIGHT) / (needleCenterY - tipY);
float baseY = HEIGHT;
needleSprite.drawWideLine(baseX, baseY, tipX, tipY, 1, NEEDLE_COLOR, TFT_ORANGE);
// 3. Draw the main needle
rad = mainAngle * DEG_TO_RAD;
tipX = needleCenterX - needleLength * cos(rad);
tipY = needleCenterY - needleLength * sin(rad);
baseX = needleCenterX + (tipX - needleCenterX) * (needleCenterY - HEIGHT) / (needleCenterY - tipY);
baseY = HEIGHT;
needleSprite.drawWideLine(baseX, baseY, tipX, tipY, 3, NEEDLE_COLOR, TFT_ORANGE);
// 4. Push the sprite to the screen
needleSprite.pushSprite(0, 0);
}
I am aware that I’m redrawing full screen instead of dirty rectangle and would like to know if esprite can take care of it automatically.
Beta Was this translation helpful? Give feedback.
All reactions