# Image not showing

**URL:** <https://discourse.processing.org/t/image-not-showing/32204>\
**Category:** Coding Questions\
**Created:** [September 11, 2021, 8:52pm UTC](https://discourse.processing.org/t/image-not-showing/32204 "2021-09-11T20:52:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Post date:** [September 11, 2021, 8:52pm UTC](https://discourse.processing.org/t/image-not-showing/32204/1 "2021-09-11T20:52:21Z")

</div>

why is my enemy image not showing?

```auto
//characters
PImage[] midas= new PImage[8];
PImage[] daughter= new PImage[3];
PImage[] enemy= new PImage[8];

boolean showMidas1= true;

//coordinates
float midasx= 1;
float midasy= 1;

float daughterx= width;
float daughtery= height;

float enemyprevx;
float enemyx= width-(width/4);

//i's
int i=1;
int i2= 1;
int i3= 1;

void setup() {
  size(600, 600);

  //load characters in
  midas[1] = loadImage("1.png");
  midas[2] = loadImage("2.png");
  midas[3] = loadImage("3.png");
  midas[4] = loadImage("4.png");
  midas[5] = loadImage("5.png");
  midas[6] = loadImage("6.png");
  midas[7] = loadImage("7.png");

  daughter[1] = loadImage("daughter.png");
  daughter[2] = loadImage("daughter gold.png");

  enemy[1]= loadImage("enemy1.png");
  enemy[2]= loadImage("enemy2.png");
  enemy[3]= loadImage("enemy3.png");
  enemy[4]= loadImage("enemy4.png");
  enemy[5]= loadImage("enemy5.png");
  enemy[6]= loadImage("enemy6.png");
  enemy[7]= loadImage("enemy7.png");
}
void draw() {
  background(0, 0, 0);
  tint(255, 255);
  //show and move the characters

  if ( (int) random(1, 3)== 1) {
    enemyx=enemyx+10;
  } else if ( (int) random(1, 3)== 2) {
    enemyx=enemyx-10;
  }

  if (enemyprevx== enemyx) {
    i3= 1;
    image( enemy[i3], enemyx, height-(height/4), 55, 85 );
  } else if (enemyprevx<enemyx) {
    pushMatrix();
    translate( enemyx + enemy[i3].width, height-(height/4));
    scale( -1, 1 );
    image( enemy[i3], enemyx, height-(height/4), 55, 85 );
    popMatrix();
  } else if (enemyprevx>enemyx) {
    image(enemy[i3], enemyx, height-(height/4), 55, 85);
  }

  if (dist(midasx, midasy, daughterx, daughtery) < 45) {
    i2=2;
  }

  image(daughter[i2], daughterx, daughtery, 40, 70);

  if (showMidas1==true&& ! keyPressed) {
    image(midas[1], midasx, midasy, 50, 80);
  } 
  if (keyPressed) {
    if (key == 'w') {
      midasy=midasy-10;
      image(midas[i], midasx, midasy, 50, 80);
      showMidas1= false;
    }
  }
  if (keyPressed) {
    if (key == 's') {
      midasy=midasy+10;
      image(midas[i], midasx, midasy, 50, 80);
      showMidas1= false;
    }
  }
  if (keyPressed) {
    if (key == 'a') {
      midasx=midasx-10;
      image(midas[i], midasx, midasy, 50, 80);
      showMidas1= false;
    }
  }
  if (keyPressed) {
    if (key == 'd') {
      midasx=midasx + 10;
      image(midas[i], midasx, midasy, 50, 80);
      showMidas1= false;
    }
  }

  i++;
  delay(100);
  if (i==7) {
    i=1;
  }
}

void keyReleased() {
  showMidas1 = true;
}

```

---

<div class="post-metadata">

**Author:** ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Post date:** [September 12, 2021, 6:40am UTC](https://discourse.processing.org/t/image-not-showing/32204/3 "2021-09-12T06:40:51Z")

</div>

if i delete it it goes way too fastl.

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [September 12, 2021, 6:54am UTC](https://discourse.processing.org/t/image-not-showing/32204/4 "2021-09-12T06:54:57Z")

</div>

That’s fine! We can fix that properly!

Instead of using `delay()`, check the value of `millis()` and only update things if it’s changed by over 100.

```auto
int last_time = 0;

void setup(){
  // ...
}

void draw(){
  if( millis() > last_time ){
    last_time = millis() + 100;
    // Do other things that should happen only once every 100 milliseconds.
  }
}
```

---

<div class="post-metadata">

**Author:** ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Post date:** [September 12, 2021, 6:56am UTC](https://discourse.processing.org/t/image-not-showing/32204/5 "2021-09-12T06:56:10Z")

</div>

why is this better than using delay()?

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [September 12, 2021, 7:21am UTC](https://discourse.processing.org/t/image-not-showing/32204/6 "2021-09-12T07:21:53Z")

</div>

The delay function is pausing everything from happening. It just wait for the desired time to pass and then resume onto the next line of your program.

It is usually bad practice because you are “loosing” that time.

Using millis() as @TfGuy44 suggested, allow your program to keep running while running the desired part of your code only every 100 milliseconds. But if you need another part of your code to do something else in the meanwhile, nothing is preventing it this time.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [September 12, 2021, 9:04am UTC](https://discourse.processing.org/t/image-not-showing/32204/7 "2021-09-12T09:04:53Z")

</div>

Some resource material:

> **[Animation](https://happycoding.io/tutorials/processing/animation)**
>
> Learn how to create animations in Processing.

References:

- [https://processing.org/reference/setup\_.html](https://processing.org/reference/setup_.html)
- [https://processing.org/reference/draw\_.html](https://processing.org/reference/draw_.html)
- [https://processing.org/reference/frameRate\_.html](https://processing.org/reference/frameRate_.html)  
[https://processing.org/reference/noLoop\_.html](https://processing.org/reference/noLoop_.html)
- [https://processing.org/reference/delay\_.html](https://processing.org/reference/delay_.html) \< This discussed use of delay()

There are may topics related to timing and timers in the forum.

`:)`
