Endless Runner Costume Extension

Category: Tutorials

Last updated 2 weeks ago

Lavanthan Saynthan

Lavanthan Saynthan Asked 2 weeks ago

For the Endless runner, if we have more than 2 running costumes then what do we do?


Jeff Plumb

Jeff Plumb Answered 2 weeks ago

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

Notify me of updates
Add to Favourites
Back to Questions

No comments yet!


Become a free member to post a comment about this question.