Newer
Older
M5StickCPlus_FactoryTest2022 / SampleSrc / sprite01.ino
@motoki miura motoki miura on 5 Apr 2023 1 KB mod
#include <M5StickCPlus.h>

// Aボタンでスプライトの使用ON/OFFします。

int USE_SPRITE = 0 ; // 1=スプライトを使用する

TFT_eSprite spu = TFT_eSprite(&M5.Lcd); // Sprite object

void setup() {
  M5.begin(115200);
  M5.Lcd.setRotation(3);
  
  spu.setColorDepth(8);
  spu.createSprite(240, 135);
  
  randomSeed(analogRead(0));
}

void loop() {
  int r = random(100000);
  if ( USE_SPRITE ) {
    spu.fillSprite( CYAN );
    spu.setCursor(30, 34, 4);  spu.setTextSize(2);
    spu.setTextColor( WHITE, BLUE );
    spu.printf("  %d  \n Sprite ", r );
    spu.pushSprite(0, 0);
    if (r % 10 == 0) Serial.println("Sprite");
  } else {
    M5.Lcd.fillScreen( CYAN );
    M5.Lcd.setCursor(30, 34, 4);  M5.Lcd.setTextSize(2);
    M5.Lcd.setTextColor( WHITE, BLUE );
    M5.Lcd.printf("  %d  \n LCD ", r);
    if (r % 10 == 0) Serial.println("LCD");
  }
  
  M5.update();
  if (M5.BtnA.wasReleased()) {
    USE_SPRITE = 1 - USE_SPRITE ; // スプライト使用の切り替え(1なら0、0なら1)
    M5.Beep.tone(1000 + 1000 * USE_SPRITE, 500);
  }
  M5.Beep.update();
  delay(100);
}