Color sprites white for damage - windows target

  • I'm trying to find a way to indicate damage with the enemies in my game. I would like to flash them a solid white as that's a well established indicator. I don't want to use an alpha flicker as the enemies don't enter an invincible state after being hit, which is what that reads as. I'm targeting Windows as my primary build. This eliminates the ColorMatrixFilter as that only works for Flash targets. Does anyone have a suggestion for how to accomplish the white flash on Windows or have an alternate suggestion for conveying damage?

  • @p3nguinc4g3

    I have a game and all my enemies have a very simple 2 frame animation. So I made a 6 frame sprite sheet for them with frames 0, 1 being full health, frames 2, 3 are drawn will a little blood, frames 4, 5 drawn with more blood. I add 3 different animations of 2 frames and play them according to health of the enemy when it changes.

    I tried lots of things but this worked best for me with the simple animations.

  • This is partial code in my Mob class, if you're interested. I'd be interested in other options, too, if anyone has any. I don't want to use FlxBar though.

    private static inline var FULL_HEALTH:Float = 3;
    public function new(x:Float, y:Float)
    	super(x, y);
    	var frameRate = 8;
    	animation.add("hurt0", [0, 1], frameRate, true); // ~ 66.67% - 100% health
    	animation.add("hurt1", [2, 3], frameRate, true); // ~ 33.33% - 66.67% health
    	animation.add("hurt2", [4, 5], frameRate, true); // ~ 0% - 33.33% health
    override public function hurt(damage:Float):Void 
    	if (health <= 0 || !alive)
    	var health33Pct = FULL_HEALTH / 3;
    	var newHealth = health - damage;
    	if (newHealth <= health33Pct)"hurt2");
    	else if (newHealth <= 2 * health33Pct)"hurt1");

  • Thanks for the reply! I had considered this but my game characters are made up of multiple pieces and I really need to telegraph that the enemy is receiving the damage and less their overall health. In other games I was able to get away with creating a whole sheet of animations that were colored white and showing those but that's just not going to work for this. I'm going to try looking into shaders and see if I can write one that allows me to pass something in to apply a white flood. I'm not sure how it will go, as documentation for shaders is still fairly sparse. If that all fails, I think I'll have to show some sort of sprite on top of the enemies with a particle explosion and a particular "damage" sound. I know the Castlevania series did this and it was fairly effective.

  • You can do it by using sprite filters. Here's some code from the old version:

    filterFrames = FlxFilterFrames.fromFrames(this.frames, 0, 0, [new ColorMatrixFilter(
    				[1, 0, 0, 0, v,
                	0, 1, 0, 0, v,
                	0, 0, 1, 0, v,
                	0, 0, 0, 1, 0])]);
    		filterFrames.applyToSprite(this, true, true);

    To make it work, you need to compile using -Dnext

    Good thing about this is that preservers animations and all that. Is for what you want. Can't remember why I stopped using it. There was a con, just can't remember what was it.

Log in to reply