DEV Community

nairrita
nairrita

Posted on

Doubt in changeImage in p5.js and matter.js

Hey !! I am developing a Javascript game using p5.js and matter.js using oop concept. I am unable to change the Image on collision. Someone help in this please!!

Top comments (1)

Collapse
 
electronbs profile image
electroNBS • Edited

You can use changeImage method in p5.js library. It can be used only on sprites, though. For example:
Syntax:
spriteName.changeImage("labelName")

Eg:
box.changeImage("newBox")

Also, please note that the newBox in the above example needs to be the same label that has the image loaded into it using the loadImage method.
Hope it helped you!