HaxeFlixel / flixel

Free, cross-platform 2D game engine powered by Haxe and OpenFL
https://haxeflixel.com/
MIT License
1.98k stars 439 forks source link

Flipped Animated Sprites in Flash target #214

Closed gamedevsam closed 11 years ago

gamedevsam commented 11 years ago

I have

loadGraphic("assets/game/sprites/turret_fire.png", true, true, 64, 64);
addAnimation("idle", [0], 0, false);
addAnimation("fire", [1, 2, 3, 4, 5, 6, 7, 8], 24, false);

And later on I set flipped = true & facing = FlxObject.RIGHT, it still doesn't play the animation flipped.

Beeblerox commented 11 years ago

I don't understand you, everything is working for me. here is my simple test:

package ;
import org.flixel.FlxG;
import org.flixel.FlxObject;
import org.flixel.FlxSprite;

/**
 * ...
 * @author Zaphod
 */

class TurretTest extends FlxSprite
{

    public function new(X:Float, Y:Float) 
    {
        super(X, Y);
        loadGraphic("assets/game/sprites/turret_fire.png", true, true, 64, 64);
        addAnimation("idle", [0], 0, false);
        addAnimation("fire", [1, 2, 3, 4, 5, 6, 7, 8], 24, false);
        play("idle");
    }

    override public function update():Void 
    {
        super.update();

        if (FlxG.mouse.x > this.getMidpoint().x)
        {
            facing = FlxObject.RIGHT;
        }
        else
        {
            facing = FlxObject.LEFT;
        }

        if (FlxG.mouse.justPressed())
        {
            play("fire");
        }
    }
}

i add these lines in my test state's create method to test this sprite:

var turret:TurretTest = new TurretTest(FlxG.width * 0.5, FlxG.height * 0.5);
add(turret);
Beeblerox commented 11 years ago

@crazysam maybe you mistook directions

gamedevsam commented 11 years ago

Ahhhhh!

I just noticed I was still assigning flipped = 0 in my constructor, after loading the animation. Maybe that internal variable should be named _flipped. Messing with it is bad :-P