How do I subtract a portion of width from a tiled object!?

Get help using Construct 2

Post » Tue Jul 15, 2014 12:48 am

Hello all, I'm having a problem with my game, the lives left system won't work properly. The game will properly add width to the tiled background (which is a heart, representing the characters lives left) when you beat a level, but for some reason it will not subtract any width from it at all (it just seems to ignore the highlighted code below which tells it to subtract 24 pixels from the tiled object/hearts). Can somebody help me to figure out why this is happening? Any help at all would be greatly appreciated.

Image
Image
Image

Thanks,
guannstar
Last edited by guannstar on Tue Jul 15, 2014 5:05 am, edited 1 time in total.
B
33
S
8
G
1
Posts: 626
Reputation: 3,775

Post » Tue Jul 15, 2014 2:03 am

Hey, I forgot to say that I also tried to simply subtract 1 (instead of trying to subtract by setting a width) from the tile object/heart's instance variable... needless to say, that didn't work either. I really need some help with this problem. I've been stuck on this for like a week now:(

Image
B
33
S
8
G
1
Posts: 626
Reputation: 3,775

Post » Tue Jul 15, 2014 4:57 am

Bump.
B
33
S
8
G
1
Posts: 626
Reputation: 3,775

Post » Tue Jul 15, 2014 6:56 am

So many events that coulde be replaced by:

LifeHeartTiled set width to: varlifeHearts*24

I guess all enemyhealth global variables are the health for enemies on the layout.
wouldn't it be easier to make that an instance variable and add 1 to varlifehealths on enemy destroyed?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Jul 15, 2014 3:26 pm

"So many events that coulde be replaced by: LifeHeartTiled set width to: varlifeHearts*24"

What do you mean by that? Could you explain further? Doesn't that mean it will just set the width to 24 pixels no matter what?

Also, are you saying to turn all my enemyhealth global variables into instance variables? Or are you saying that when I destroy a level's enemies, just add 1 to varlifehealths's instance variables instead of setting variables to the next specific number?
B
33
S
8
G
1
Posts: 626
Reputation: 3,775

Post » Tue Jul 15, 2014 3:43 pm

All your events are being checked all the time.

what you should do is something like this:

Give the enemy an instance variable Health

enemy : variable Health =< 0
- enemy destroy

On enemy destroyed
- system subtract 1 from varlifehearts
- LifeheartTiled set width : varlifehearts*24

Are all your enemies different sprites or are they the same enemy cloned?
For if they are cloned, I would recommend using copies rather than clones so they all respond to the same actions. (I'm assuming you don't have a paid version, for if so you could use families for that)
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Jul 15, 2014 4:12 pm

I do have a paid version, and I am using families. But, I don't want to subtract 1 from varlifeHearts on enemy destroyed, I want to subtract 1 from varlifeHearts when my character dies (the tiled hearts represent the character's lives left, not the enemy's).
B
33
S
8
G
1
Posts: 626
Reputation: 3,775

Post » Tue Jul 15, 2014 4:43 pm

I do have a paid version, and I am using families. But, I don't want to subtract 1 from varlifeHearts on enemy destroyed, I want to subtract 1 from varlifeHearts when my character dies (the tiled hearts represent the character's lives left, not the enemy's).


Then you just need to do a slight adjustment to LittleStain's example:

enemy : variable Health =< 0
- enemy destroy

On enemy destroyed
- system add 1 to varlifehearts (since the events you posted seem to be increasing lives when enemies are destroyed)
- LifeheartTiled set width : varlifehearts*24

character : variable Health =< 0
- system subtract 1 from varlifehearts
- LifeheartTiled set width : varlifehearts*24
Vote for all the Construct 2 games on Steam Greenlight - Find them here
B
33
S
9
G
7
Posts: 450
Reputation: 6,778

Post » Tue Jul 15, 2014 4:48 pm

OK thanks guys, I'll try it and see if it works out.
B
33
S
8
G
1
Posts: 626
Reputation: 3,775

Post » Tue Jul 15, 2014 6:02 pm

I haven't read the whole post, but someone asked for a similiar (if not identical) thing a few days ago.
Check if that helps.
You do not have the required permissions to view the files attached to this post.
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Next

Return to How do I....?

Who is online

Users browsing this forum: tdcostas and 9 guests