Blinking images are too fast

I want to blink some images in my Simon game, but they are blinking very short. You can hardly see that a light (image) is turned on.

boolean isPlayerReady = false;
ArrayList<Integer> gameList;
ArrayList<Integer> playerList;
int ROUNDS = 20; 
int counter = 4;
int gameListPosition = 0;

PImage bg;
PImage green;
PImage red;
PImage blue;
PImage yellow;

int startTime;
int timeOut;

void setup()
{
  gameList = new ArrayList<Integer>();
  
  for (int i = 0; i < ROUNDS; i++)
  {
      gameList.add(int(random(1, 5)));
  }
  
  size(685, 565);
  bg = loadImage("img/Simon.png");

  green = loadImage("img/green.png");
  red = loadImage("img/red.png");
  blue = loadImage("img/blue.png");
  yellow = loadImage("img/yellow.png");

  startTime = millis();
  timeOut = millis() + 1000;
}

void draw()
{
  background(bg);

  if (!isPlayerReady)
  {
    if (millis() >= timeOut)
    {
      int tone = gameList.get(gameListPosition);
      gameListPosition++;

      if (tone == 1)
      {
        image(green, 90, 30);
      }
      else if (tone == 2)
      {
        image(red, 325, 30);
      }
      else if (tone == 3)
      {
        image(yellow, 90, 260);
      }
      else if (tone == 4)
      {
        image(blue, 325, 260);
      }
      
      if (gameListPosition == counter)
      {
          isPlayerReady = !isPlayerReady;
      }
      
      timeOut = millis() + 1000;

    }
  }

Has somebody any hints to show the images a few seconds longer?

1 Like

Whats going on at this line?

1 Like

Take at look at this example:

//State Changes

int startTime;
int timeOut;
int count;
int bg;

boolean state = false;

void setup()
  {
  size(200, 200);
  startTime = millis();
  timeOut = millis() + 5000;
  }

void draw()
  {
  background(bg);
  if (millis() >= timeOut)
    {
    timeOut = millis() + 5000;
    println(count++);
    state = true;
    }
    
   if (state)
     {
     bg = int(random(0, 255));
     state = false;  
     }
  }

:)

2 Likes

In this line the timeOut will be increased with a new time limit, because of the condition if (millis() >= timeOut).

Thank you in advance! :slight_smile: If I have still any problems I let you know. I will test your code and I hope, this will work for images as well.