Search code examples
arduinoesp32arduino-c++

Display Issue with TFT_eSPI.h Library: Sprite Not Displaying Correctly After Adjusting Dimensions


Recently I received a round 240x240 pixel GC9A01 display. However, I'm encountering an issue when using sprites with the library TFT_eSPI.h. In fact, the problem arises from this tutorial: https://www.youtube.com/watch?v=U4jOFLFNZBI&t=864s&ab_channel=VolosProjects. At one point, a sprite is created as a background with the length and width of the screen to "slide" another sprite over it. My issue is that I can't seem to create a sprite covering the entire screen surface.

Everything works perfectly in this code:

#include <TFT_eSPI.h>

TFT_eSPI tft = TFT_eSPI(); 
TFT_eSprite background = TFT_eSprite(&tft);

void setup() {
  Serial.begin(9600);
  tft.init();
  tft.fillScreen(TFT_BLACK);
  background.createSprite(240, 230); //the line 
}

void loop() {
  background.fillSprite(TFT_BLACK);

  background.pushSprite(0, 0);

  Serial.print("Width Sprite: ");
  Serial.print(background.width());
  Serial.print(" Height Sprite: ");
  Serial.print(background.height());
  Serial.print(" Width TFT: ");
  Serial.print(tft.width());
  Serial.print(" Height TFT: ");
  Serial.println(tft.height());
}

However, if I change from background.createSprite(240, 230); to background.createSprite(240, 231);, nothing works anymore, and it shows in the serial port that the sprite is 0x0 pixels. Any help is greatly appreciated. I have indeed modified the User_Setup.h file to use my screen.

Example of the serial monitor with 231 pixels and more:

231 pixels and more

Example of the serial monitor with 230 pixels :

230 pixels


Solution

  • try reducing the depth color to 8 before creating the sprite:

    background.setColorDepth(8);