Color Based Damage *Solved*

Get help using Construct 2

Post » Tue Dec 31, 2013 3:24 pm

Problem - Causing an enemy to become redder, as it becomes more damaged - a visual indicator to how much life it has left

Like so....


---Solved thanks to
-Little Stain
-Insignia
-Squidget

Method
Create 2 objects
1 Enemy object ----------- valkyrie
1 Enemy damaged object --- ValkyrieDamg

Set the enemy damaged object into a container of the enemy object

Valkyrie - on created ->>ValkyrieDamg - set position to Valkyrie
>>Set Angle to Valkyrie.Angle degrees

System Every Tick - >> Set Opacity -- Self.initialOpacity+((valkyrie.maxHealth-valkyrie.health)/valkyrie.maxHealth)*100

This method allows you to transpose a damaged version in varying opacities over the original object.

An alternative method is to use the tint effect to cause the color change.
Effregy2013-12-31 22:55:38
B
9
S
2
G
1
Posts: 36
Reputation: 1,381

Post » Tue Dec 31, 2013 3:30 pm

You could add a completely red sprite in the form of the ship, set it's blend mode to additive and set it's opacity based on the damage.
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 Dec 31, 2013 3:31 pm

One way you could do it is have a identical 'red' (or fully damaged) version of your main ship and every tick set the red sprite to the normal sprite's location with it's opacity set to 0. Then, every however many hits (or when your health gets to a certain percentage), just increase the 'red' ship's opacity accordingly.
There's probably a more elegant way but with this method you have complete control over the colour change.

EDIT: Damn, 1 minute too late and LittleStain's method would work better :)Insignia2013-12-31 15:33:11
B
3
Posts: 7
Reputation: 1,114

Post » Tue Dec 31, 2013 3:38 pm

@Insignia, I wouldn't say my method is better, both are plausible solutions.
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 Dec 31, 2013 3:54 pm

Sweet- I'll try both out

Thanks for the help Effregy2013-12-31 16:00:13
B
9
S
2
G
1
Posts: 36
Reputation: 1,381

Post » Tue Dec 31, 2013 4:05 pm

How were you hoping to make sprites more red, without adding sprites or animations or effects?
Effects per sprite would probably be a bigger strain on your system than just adding 1 completely red sprite.
Animations would mean adding a lot more sprites than that.
Also doing it the way I explained you wouldn't have to use WebGL.

If you'd rather use webgl per sprite you could use the tint effect or the hsl effect (maybe there are others that would even suit you better), but it would probably be a lot more intensive for your processor.
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 Dec 31, 2013 4:38 pm

I come from a background of game maker and there is a function you can call or script yourself that changes the color through programming

I figured there would be something similar in Construct 2 that would allow the same affect.

However, just using opacity is a perfectly good way + you got me to look up blend modes. And for what I'm trying to achieve that method works perfectly fine.

Witch is why I edited my original reply =p

Thanks again Effregy2013-12-31 16:38:53
B
9
S
2
G
1
Posts: 36
Reputation: 1,381

Post » Tue Dec 31, 2013 7:02 pm

Because my brain is broken, this took a moment to figure out, so for funsies, I'll release the final result I came up with....

System Every Tick >> heliBossDamage - Set Opacity >> Self.initialOpacity+((heliBoss.maxHealth-heliBoss.health)/heliBoss.maxHealth)*100Effregy2013-12-31 19:02:49
B
9
S
2
G
1
Posts: 36
Reputation: 1,381

Post » Tue Dec 31, 2013 7:13 pm

That's probably about the same effect as this formula to calculate from one range of numbers to another. (which I didn't think up myself, but use a lot now)


//(x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min //
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 Dec 31, 2013 7:59 pm

I'm going to have to play with that before I grasp it fully and see what it'd be useful for

However...I broke my brain again... I added multiple enemies, and I can't figure out how to get the enemy to spawn the damage version and have it only be affected by the enemy that spawned it

Valkyrie A B and C spawn
ValkyrieA spawns DamgValkyrie
ValkyrieA loses 20 health of 35
ValkyrieA should be the only one with a damg version showing

however, A B and C are all becoming Damaged =/

Valkyrie - on created
>>Valkyrie - spawn ValkyrieDamg
>>ValkyrieDamg - set position to Valkyrie
>>Set Angle to Valkyrie.Angle degrees
>> ValkyrieDamg set affector to self.UID
>> Valkyrie set affectorCall to ValkyrieDamg.UID

Valkyrie - health < self.maxHealth
-ValkrieDamg self.Affector = Valkyrie.affectorCall
>> Set Opacity -- Self.initialOpacity+((valkyrie.maxHealth-valkyrie.health)/valkyrie.maxHealth)*100

Edit: Haven't figured out what that expression would be useful for lol
//(3 - 2) * (15 - 8) / (7 - 2) + 8 //
gives 9.4 - first I'd though maybe range of damage verse armor, but then you'd prob use something like
-damg = random(2,8) -armor = 5 -pierce of 20%
so something like damg-armor+(pierce*damg)= dealt damg
so base 7 - 5 + (0.2 * 7) = 3.4 total damgEffregy2013-12-31 20:21:14
B
9
S
2
G
1
Posts: 36
Reputation: 1,381

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests