Three lifes problem

Get help using Construct 2

Post » Wed Aug 08, 2012 7:50 am

Hello,

at first I apologise for very stupid begginer question. I am trying to create lifes of player and show them in the hud (I am basically show smaller version of player's airplane as one life. Basically player sprite has variable "life" starting value is 3. So at beginning there is three of them.

then in events I have something like this:



and then in another condition I have something like if player collides with enemy substract 1 from "life variable.

It works but I think this sollution is kinda sketchy and not right in sense of programming sense?

I suppose I should use for or foreach loop somehow? Thank youMichal112012-08-08 08:02:25
B
8
S
2
Posts: 45
Reputation: 1,168

Post » Wed Aug 08, 2012 8:08 am

I think at every tick now, its going to be creating more and more objects because it still meets that condition.

The best way would to be using 3 already pre-made objects on the screen and adjusting their visibility based on it meeting the life requirement.

You also don't need it on every tick, you could just have them only check when an event which affects life is done. So as a sub-event of your GOT ATTACKED event, you reduce life by 1, and if life is = 2, set visibility of invisible to one etc.
B
36
S
10
G
6
Posts: 948
Reputation: 11,101

Post » Wed Aug 08, 2012 8:11 am

hmm, I think this will slow down your game a lot to create the sprites every tick.

Is your game fixed to a max of 3 lifes? If it is, I would suggest to just put 3 instances of the sprite to your game directly and give them individual names. Based on the life variable, you should then just toggle the visibility to true/false. This will speed up everything a lot.


EDIT: Damn Ninjas :)


EDIT 2:

Another solution, that would be faster:
Set up the Life Sprite as a tiles background object. Based on your life, you can then just set the width of the object to show the correct number of hearts. With this, you would only need one action that calculates the necessary width of the background by (width of heart * # of lifes).Ubivis2012-08-08 08:14:40
B
42
S
9
G
6
Posts: 437
Reputation: 5,626

Post » Wed Aug 08, 2012 8:13 am

@Ubivis bright minds think alike, fellow ninja. Haha!
B
36
S
10
G
6
Posts: 948
Reputation: 11,101

Post » Wed Aug 08, 2012 8:33 am

Just made an example of my second suggestion, works very nice :)


Download
B
42
S
9
G
6
Posts: 437
Reputation: 5,626

Post » Wed Aug 08, 2012 8:56 am

Thanks guys. I am starting to love this friendly community :). I hope one day I will be helpful to others as youMichal112012-08-08 08:56:57
B
8
S
2
Posts: 45
Reputation: 1,168


Return to How do I....?

Who is online

Users browsing this forum: armaldio, blackhornet, TiagoCesar, Zebbi and 18 guests