For Loop & Life Totals

  • So I am trying to learn and am building old school space invaders. So I want to show the remaining life (Number of Ships) the player has and I cant get it. I am for sure way over thinking, that is my MO, help please.

    I would like to display an icon for each Life the player has remaining, start with 3. Each time player loses a life, remove an icon. Simple enough but in C2, How?

    I first thought, oh easy just do a For loop create 3 icons, then remove 1 each time player loses life. BUT destroy removes all 3 in one swoop.

    How can I post an img to show you my logic? I also don't also get how and when "System" is executed, it is every tick?

    Thanks

    Brett

    <img src="https://www.dropbox.com/s/hjitf08re77tzek/forumhelp.png" border="0" />

  • You need to pick the specific instances of the icon you'd like to destroy. One way would be to set an instance variable on the icons as they're being created in the loop, and when you're ready to destroy one of them, choose the icon with a specific value in its instance variable to destroy.

    However, I think there's a much more efficient way to do it using a global variable for lives, and running a function whenever the number of lives change.

    Demo

    Capx.

    I hope this helps.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Wow, outstanding you went above and beyond thank you. I totally forgot about Functions that makes total sense. Thank you, owe you

    Brett

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)