Hi all…
How to switch image that I have many images to display alternately?
I use setTexture(), but it only switch from image 1 to image 2, I want to switch again from image 2 to image 3, etc…
nextSprite() {
this.dubai.setTexture("paris")
this.dubai.setTexture("ny")
}
You can keep a state in a displayedImage
instance variable or even in a data manager data, or just a state of the game object itelf. You can write nextSprite
to make a check displayedImage
to know which is currently displayed. Or if there is a way to get the texture of an object you can use it too. Accordingly call the setTexture
:
nextSprite() {
if (this.displayedImage === "ny") {
this.dubai.setTexture("paris")
} else {
this.dubai.setTexture("ny")
}
}
If you have only two and toggle between them.