首页 > 解决方案 > 使用 eSprite 在 TFT 上移动元素

问题描述

我开始将TFT_eSPI用于我的一个 ESP32 项目。我对这个库没有太多经验,但希望使用在背景图像上浮动/移动绘制几个元素(如实心圆圈)(不弄乱背景)我尝试使用 TFT_eSprite 作为前景并推动它们,但注意到它在背景上留下痕迹。

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

void drawCirle(int x, int y)
{
  img.setColorDepth(8);
  img.createSprite(36, 36);
  img.fillSprite(TFT_TRANSPARENT);
  img.fillCircle(18, 18, 8, TFT_BLUE);
  img.pushSprite(x, y, TFT_TRANSPARENT);
  img.deleteSprite();
}

int y, x = 8;
void setup()
{
  tft.init();
  tft.setRotation(0);

  tft.fillScreen(TFT_RED); // let say that's the background
}

void loop()
{
  drawCirle(x, y++); // this is forground

  if (y > 240)
  {
    y = 0;
    x += 16;
  }
  delay(100);
} 

有没有更好的方法来处理这个问题?

标签: c++esp32

解决方案


推荐阅读