Page 1 of 2

Color Based Damage *Solved*

PostPosted: Tue Dec 31, 2013 3:24 pm
by Effregy
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

Re: Color Based Damage *Solved*

PostPosted: Tue Dec 31, 2013 3:30 pm
by LittleStain
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.

Re: Color Based Damage *Solved*

PostPosted: Tue Dec 31, 2013 3:31 pm
by Insignia
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

Re: Color Based Damage *Solved*

PostPosted: Tue Dec 31, 2013 3:38 pm
by LittleStain
@Insignia, I wouldn't say my method is better, both are plausible solutions.

Re: Color Based Damage *Solved*

PostPosted: Tue Dec 31, 2013 3:54 pm
by Effregy
Sweet- I'll try both out

Thanks for the help Effregy2013-12-31 16:00:13

Re: Color Based Damage *Solved*

PostPosted: Tue Dec 31, 2013 4:05 pm
by LittleStain
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.

Re: Color Based Damage *Solved*

PostPosted: Tue Dec 31, 2013 4:38 pm
by Effregy
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

Re: Color Based Damage *Solved*

PostPosted: Tue Dec 31, 2013 7:02 pm
by Effregy
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

Re: Color Based Damage *Solved*

PostPosted: Tue Dec 31, 2013 7:13 pm
by LittleStain
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 //

Re: Color Based Damage *Solved*

PostPosted: Tue Dec 31, 2013 7:59 pm
by Effregy
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