# The command image() do not works

**URL:** <https://discourse.processing.org/t/the-command-image-do-not-works/30608>\
**Category:** Libraries\
**Created:** [June 9, 2021, 4:32pm UTC](https://discourse.processing.org/t/the-command-image-do-not-works/30608 "2021-06-09T16:32:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevincroos](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevincroos/32/13292_2.png) [@Kevincroos](https://discourse.processing.org/u/Kevincroos)\
**Post date:** [June 9, 2021, 4:32pm UTC](https://discourse.processing.org/t/the-command-image-do-not-works/30608/1 "2021-06-09T16:32:40Z")

</div>

- [homework policy](https://discourse.processing.org/faq/#homework)
- [asking questions](https://discourse.processing.org/t/2147)

# hello developers

## I had a problem with the image() command

### One answer is very important to me : \_ (

My image does not load on the screen, I check the console but I have no errors, my image is prompted and live according to the console, I don't know if this problem is because my program has the P5.Play library or because the drawSprites() command, I use scenes in my program and always put the command image() in front of the background

_Half of my code is below_

```auto
var player
var target
var scene = 1
let img

function preload() {
  img = loadImage('assets/Pixel Studio/ButtonUnpressed.gif')
  
}

function setup(){
  createCanvas(960, 430)
  cursor('none')
  
  target = createSprite(850, 100)
  targetImg = loadImage('assets/128/dagger.png')
  target.addImage(targetImg)
  player = createSprite(150, 150)
  playerImg = loadImage('assets/128/dagger.png')
  player.addImage(playerImg)
  }

function draw(){

if (scene === 1) {
   background(230)
     image(img, 200, 200)

```

_I am using the P5.play library, if you have experience in this library, please talk to me_.

\*No console errors.

\*Image requested and maintained in console.

\*I use scenes.

\*I am available in the private chat.

\*I really need answers.

- Have a nice day.

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [June 9, 2021, 5:23pm UTC](https://discourse.processing.org/t/the-command-image-do-not-works/30608/2 "2021-06-09T17:23:00Z")

</div>

Hi @Kevincroos ,

First simple question :

```auto
if (scene === 1) {

```

is this condition true?

Can you print the `img` variable in the `setup()` function? Are you sure you are not overriding it or hiding it with something else?

Try to make another simple sketch where you only load and display your image and see if that works. 😉

---

<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:** [June 10, 2021, 10:25am UTC](https://discourse.processing.org/t/the-command-image-do-not-works/30608/3 "2021-06-10T10:25:28Z")

</div>

> [@Kevincroos](#):
>
> I use scenes in my program and always put the command image() in front of the background

In front of is not clear…

This will give you a black background on top of your image and result in a black screen:

```auto
image(img);
background(0);

```

Read the reference:  
`https://p5js.org/reference/#/p5/background`

`:)`

---

<div class="post-metadata">

**Author:** ![Kevincroos](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevincroos/32/13292_2.png) [@Kevincroos](https://discourse.processing.org/u/Kevincroos)\
**Post date:** [June 10, 2021, 10:35pm UTC](https://discourse.processing.org/t/the-command-image-do-not-works/30608/4 "2021-06-10T22:35:36Z")

</div>

Yes, it’s a true condition…

I tryed your options ⬇

I put img() in the Setup (but nothing happened), kept only one scene (no modification too), so I tried calling my image only, no sprites, element or other objects (but it dont has displayed), I think of my problem is about the program don’t search for my img variable from the preLoad() function, am I correct? It’s really a mess because when I called preLoad() for the first time, my image was displayed and it worked correctly.

---

<div class="post-metadata">

**Author:** ![Kevincroos](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevincroos/32/13292_2.png) [@Kevincroos](https://discourse.processing.org/u/Kevincroos)\
**Post date:** [June 10, 2021, 10:43pm UTC](https://discourse.processing.org/t/the-command-image-do-not-works/30608/5 "2021-06-10T22:43:19Z")

</div>

Well, i always use

```auto
background(255);
image(img, 0, 0);

```

**I guess you are confunded about my post _“In front of the background”_, sorry me😀.**

But you got it help me too, i readed your reference ([reference | p5.js](https://p5js.org/reference/#/p5/background)) and i got it another ways to display my image(how sprite), thanks by your help too😁
