Color Based Damage *Solved*

0 favourites
From the Asset Store
This sound pack features 117 game sounds : Axe,Punch Swing & Hit & Damage. This is a perfect collection for your game.
  • Problem - Causing an enemy to become redder, as it becomes more damaged - a visual indicator to how much life it has left

    Like so....

    <img src="http://s28.postimg.org/xme4qrsjh/health_Color.png" border="0" />

    ---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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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 :)

  • Insignia, I wouldn't say my method is better, both are plausible solutions.

  • Sweet- I'll try both out

    Thanks for the help <img src="smileys/smiley2.gif" border="0" align="middle" />

  • 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 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 <img src="smileys/smiley36.gif" border="0" align="middle" />

  • 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)*100

  • 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'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 damg

  • You just have to add a for each valkyre to the last event. You are not picking a specific instance in your event so it affects all instances.

    the formula I posted works if you want to find a number.

    let's say you have numbers from 0 to 100 and you have to translate it to numbers from 25 to 250. in-min is 0 out-min is 25, in-max is 100 out-max is 250, so if you've got input 10 output would be 37.5

  • translate number between ranges. so translate from health number to opacity.

  • I'm going to have to look up a tutorial on For Each, I've never used it lol

    Also

    With what I was trying to achieve -- more damg = more opaque, a percentage based method makes more sense, since the opacity is based off a range of 0 invis - 100 opaque

    besides I took a simple problem

    20 out of 100 you'd want 80

    10 / 100 you'd want 90

    15/35 you'd want 57.1ish

    ect

  • <img src="http://s18.postimg.org/6a3n4pnl5/problem.png" border="0" />

    This doesn't work <img src="smileys/smiley5.gif" border="0" align="middle" />

    what happens, is it's either at 0 opacity or max

    and even when the valkyrie should have full health, it's at max opacity

    I knew why it was having trouble connecting each valkyrie to it's damg version, but I don't see how to fix it. I figured it'd be something with the uid's, but even then, when one valkyrie was low on health, all of them were displaying as heavily damaged

  • Having a separate red sprite is okay, but if your ships are too big and complex it's going to be a lot of extra video memory, since each ship would represent a separate set of textures.

    I would probably try to do this with effects. A Tint effect that starts at 100,100,100 but lowers its green and blue parameter each time the ship is damaged seems like it would do something like what you want?

    As for your current method, it will be easier if you use containers and a pin behavior. Put the red ship into a container with the regular ship (this will cause both objects to be created/destroyed/picked whenever one of them is.) You can read about containers here if you haven't used them.

    Give the red ship a pin behavior. Then do events similar to this:

    On Ship Created -> RedShip Pin To Object: Ship.

    On Ship Damaged -> RedShip set opacity as needed

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