Moving oversize sprite

Hello,

trying to display varying portions of a sprite, moved via touch screen gestures, drives me crazy.

Swiping with the finger up and then down makes the text disappear, once is has been pushed beyond the screen edge. Instead, swiping down and then up again does also show that portion of text, which has temporarily moved "out" of the screen. The latter behaviour is what I had expected.

Without success I tried to solve this with deploying the scrollRectangle() function, working with explicit background colors, with transparency...
I thought, once written to the sprite, the text stays there, irrespective of sprite movement.
Am I misunderstanding the concept of a sprite?

The following is the example sketch to program an M5Core2 with 320x240 touch screen:

#include <M5Core2.h>
TFT_eSprite asprite(&M5.Lcd);
Event& e = M5.Buttons.event;

void setup() {
   M5.begin();
   asprite.setColorDepth(8);
   asprite.createSprite(320,500); // sprite height > 2xscreen height
   asprite.setTextFont(2);
   for (int i=0; i<30; i++) {  asprite.printf("Line %d -- some string for testing\n",i+1 );  }
   asprite.pushSprite(0,0);
}

void loop() {
   M5.update();
   if (e & (E_MOVE | E_RELEASE)) {
      asprite.scroll(0,e.to.y-e.from.y);
      asprite.pushSprite(0,0);
   }
}

I would be grateful for any advice. Thanks and best,
didigs

...meanwhile solved it myself as follows:

#include <M5Core2.h>
TFT_eSprite asprite(&M5.Lcd);

Event& e = M5.Buttons.event;
int dy,sumdy;

void setup() {
   M5.begin();
   M5.Lcd.setTextFont(2);
   asprite.setColorDepth(1);
   asprite.createSprite(320,480);   // sprite height > screen height
   asprite.setTextFont(2);
   for (int i=0; i<30; i++) { asprite.printf("Line %2d --- part of a longer string...\n",i+1); }
   asprite.pushSprite(0,0);
   sumdy=0;
}

void loop() {
   M5.update();
   if (e &  (E_MOVE | E_TOUCH)) {
      dy = e.to.y-e.from.y;
      dy = 16*round(dy/16);    // make it multiples of line spacing (=16 here), easier on the eye
      dy = max(dy,-240-sumdy); // never swipe up beyond last line (=30)
      dy = min(dy,-sumdy);     // never swipe down beyond first line (=0)
      sumdy = sumdy+dy;        
      asprite.pushSprite(0,sumdy); // also overwrites non-text pixels with bg-color
   }
}

My error was to assume that scroll(...) would move the sprite. Instead, it moves the text within the sprite and eventually beyond it's edges, that's why text got lost in my first sketch. Solution is to use the swipe-determined displacement in the pushSprite(...) call...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.