Author Topic: Flipping sprites Ingame and hit flashes?  (Read 2812 times)

Dr_shenanigans

  • Member
  • **
  • Posts: 92
  • Karma: +0/-0
    • View Profile
Flipping sprites Ingame and hit flashes?
« on: Mon, Aug 29, 2011 »
I noticed with the flixel power tools, (specifically control scheme 2 - the platforming one) that it was possible to flip the sprite without needing a whole set of new anims.

I'm wondering how it's possible to do that by hand/

also, I need to know how to make a player or enemy flash when hit (not flicker, but a flash or color change when hit with a bullet/spike/enemy/etc.)

osro

  • Active Member
  • ***
  • Posts: 121
  • Karma: +1/-0
    • View Profile
    • Purppura
Re: Flipping sprites Ingame and hit flashes?
« Reply #1 on: Mon, Aug 29, 2011 »
I noticed with the flixel power tools, (specifically control scheme 2 - the platforming one) that it was possible to flip the sprite without needing a whole set of new anims.

I'm wondering how it's possible to do that by hand/


By changing FlxSprite's facing property (LEFT RIGHT)
http://flixel.org/docs/org/flixel/FlxSprite.html#facing

auriplane

  • Snails!!
  • Contributor
  • ****
  • Posts: 497
  • Karma: +1/-0
  • Snails!!
    • View Profile
Re: Flipping sprites Ingame and hit flashes?
« Reply #2 on: Mon, Aug 29, 2011 »
In FlxSprite:

Code: [Select]
        public function unFlashColor():void
        {
            _ct = null;
            calcFrame();
        }

        public function flashColor(Color:uint):void
        {
            _ct = new ColorTransform();
            _ct.color = Color;
            calcFrame();
        }

In 2.5, it's _colorTransform instead of _ct.  Add some state if you want it to revert on its own after a specified time or such.

FlxSprite has a getter/setter pair which work with _colorTransform already, but they only do color multipliers.

Arkeus

  • Contributor
  • ****
  • Posts: 321
  • Karma: +1/-0
    • View Profile
    • I, Arkeus
Re: Flipping sprites Ingame and hit flashes?
« Reply #3 on: Mon, Aug 29, 2011 »
In FlxSprite:

Code: [Select]
        public function unFlashColor():void
        {
            _ct = null;
            calcFrame();
        }

        public function flashColor(Color:uint):void
        {
            _ct = new ColorTransform();
            _ct.color = Color;
            calcFrame();
        }

In 2.5, it's _colorTransform instead of _ct.  Add some state if you want it to revert on its own after a specified time or such.

FlxSprite has a getter/setter pair which work with _colorTransform already, but they only do color multipliers.

Just to expand on this, the built in ones are very limiting, but usually more than enough to do hit flashing. Setting the "color" property of a FlxSprite to something like 0xbb3333 works well. Something like:

Code: [Select]
if (_flashTimer > 0) {
    _flashTimer -= FlxG.elapsed;
    color = 0xbb3333;
} else {
    color = 0xffffff;
}

Should do what you want.

Dr_shenanigans

  • Member
  • **
  • Posts: 92
  • Karma: +0/-0
    • View Profile
Re: Flipping sprites Ingame and hit flashes?
« Reply #4 on: Wed, Aug 31, 2011 »
excellent, thanks!

Kytin

  • Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: Flipping sprites Ingame and hit flashes?
« Reply #5 on: Sun, Nov 27, 2011 »
I'm looking to add hit flashes as well, but the method here only seems to work for making them darker, and was hoping to make them flash white. Am I missing something, or is it just not possible?
I have seen the future. You will not.

auriplane

  • Snails!!
  • Contributor
  • ****
  • Posts: 497
  • Karma: +1/-0
  • Snails!!
    • View Profile
Re: Flipping sprites Ingame and hit flashes?
« Reply #6 on: Mon, Nov 28, 2011 »
Yup, my post above is talking about how to make them flash white.  I did that for my game :-D