Last updated 3 years ago
For the Endless runner, if we have more than 2 running costumes then what do we do?
Great question Lavanthan. You can use the loadImage function to load each image you have. Then you can switch between those costumes as required. For example if you have 3 costumes, then outside your animation loop you would write code similar to the following:
hero = Sprite("costume1.png", 20, 220)
costume1 = loadImage("costume1.png")
costume2 = loadImage("costume2.png")
costume3 = loadImage("costume3.png")
Then in your animation loop you would switch costumes as needed. One possible way would be to use the following code:
if hero.image == costume1:
hero.image = costume2
elif hero.image == costume2:
hero.image = costume3
else:
hero.image = costume1
Become a free member to post a comment about this question.