Problem with delay()

Hello,
i’m trying to implement this example: https://p5js.org/reference/#/p5.Image/delay in a sketch, but when I run it i get the message “bg1.delay is not a function”. I believe my code is exactly the same as in the example. Do i need to use a specific library or something?
Thanks in advance!


let bg1, bg2;

function preload() {
  bg1 = loadImage("deck/elBueno.gif");
  bg2 = loadImage("deck/elBueno.gif");

}

function setup() {
  createCanvas(480, 720);
  bg1.resize(width / 2, height / 2);
  bg2.resize(width / 2, height / 2);

  bg1.delay(10);
  bg2.delay(100);

}

function draw() {
   
   background(0);
  translate(width / 2, height / 2);
  image(bg1, 0, 0);
  image(bg2, 0, 0, width/2,0);

}

1 Like

Hello,

It works fine here in the Processing P5.js mode.

I used this animated gif:

:)

1 Like

Thanks!!
I tried with your gif but same error :frowning:
did you use the exact same code, just changed the file?

Hello,

It still works fine here in the Processing P5.js mode and with the P5 Editor.
I modified code but it worked with original as well.

let bg1, bg2;

function preload() 
  {
  bg1 = loadImage('giphy.gif');
  bg2 = loadImage('giphy.gif'); 
  }

function setup()
  {
  createCanvas(800, 450);
  //bg1.resize(width / 2, height / 2);
  //bg2.resize(width / 2, height / 2);
  bg1.delay(10);
  bg2.delay(100);
  }

function draw() 
  {
   background(0);
  //translate(width / 2, height / 2);
  image(bg1, 0, 0);
  image(bg2, width/2, 0);
  }


:)

2 Likes