I have a problem about when I want to press a key, up, down, right and left, change the image of my Pacman, depending on its position, with different animated sprites, which are in different images, according to their position, but my Pacman character does not it is shown, and in my video game it does not show me any error in the console.
@CodeOscar in draw() you say pacman.animate(data, rightImage); , which will only animate the rightImage and ignore anything that happens inside the keyPressed function. I recommend making another image, imag or something and in function keyPressed do:
In draw you can now say: pacman.animate(data, imag); and it should update with that image
now it still does not animate properly, but that is because in the pacman.js on line 18:
animation.push(img);
will only add extra images which makes the array of animations longer and longer. you need to clear that out.
Probably when you want to select another image (so in function keyPressed()).
I’m not a p5.js master so I can’t guarantee this will make it work, or tell you how to, but this is definitely some things that are wrong.
I would not have images being passed around as variables at all! Instead, make all your images globals, load them in setup, and then use conditional statements inside your pacman class to determine which way pacman is moving & use the appropriate image.