Animation Issue



  • Hello - I've been following the tutorial for a planet defense game - https://www.youtube.com/watch?v=6YemVrJnlS8

    I've made it to episode 3 where I've added my player onto the planet. I've also created a pixel animation panel. However, when I go to add the animation of my player walking and idling, it doesn't run any animation and instead just shows the first frame listed in the array.

    Ex) My Idle animation is supposed to bop up and down but it just remains steady at the first panel. And my Walking animation just stays steady at the first panel as well. If I change the first panel in the array (to the player lifting his foot up to begin the step) it will just hold on that panel. Essentially, there is no animation being done. They're all still images that move around my planet. I've attached the panel of my pixel animations for reference. The panels are 16x16

    Player![alt text](image url)

    Thanks![alt text](![image url](![image url](image url)))



  • @haxe756 ![alt text](0_1593623934395_Player.png image url)



  • This post is deleted!


  • The function have just after the array, the parameters framerate for the speed of the animation,if you put the first it in 0 the animation don't start, next to it is looped parameter(that for the default is true), is you set it false the animation end in the last frame automatically.
    and for playing or change animations you should call animation.play("animationname"). check out if you type the name correctly, inclusive a extra space can make the animation don't start.



  • Hi - My code is as follows:

    animation.add("Idle",[0,1],2,false);
    animation.add("WalkLeft",[6,7,8,9],10,false,true);
    animation.add("WalkRight",[6,7,8,9],10,false,false);



  • @haxe75 It would be easier to help if you show more of your animation code than just that if it exists. If that is all your animation code then that would mean you are not actually starting your animations with something like animation.play("Idle");

    Another problem I see is the 4th parameter in "Idle" is for looping which I imagine you want, so it should be..

    animation.add("Idle", [0, 1] 2, true );
    animation.play("Idle");

    Then when you want to play the walking animation you say animation.play("WalkLeft"); or right.. while making sure you revert back to playing Idle when you are idle.



  • Hello -

    The rest of the code is as follows:

    if (leftKey)
    {
    angleFromPlanet -= FlxG.elapsed * speed;
    animation.play("WalkLeft");
    }
    else if (rightKey)
    {
    angleFromPlanet += FlxG.elapsed * speed;
    animation.play("WalkRight");
    }
    else
    {
    animation.play("Idle");
    }



  • Things such as FlxButton need to be updated while some other stuff do not need updating. So you might not have super.update(elapsed) or the update() function in your class.

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


  • Hello - I do have an override public function in my Player class. My entire player class is as follows:

    package;

    import Planet;
    import flixel.FlxG;
    import flixel.FlxSprite;
    import flixel.math.FlxAngle;
    import flixel.util.FlxColor;

    class Player extends FlxSprite
    {
    var angleFromPlanet:Float;
    var planet:Planet;
    var speed:Float = 1;

    public function new(_angle, _planet)
    {
    	super(0, 0);
    
    	angleFromPlanet = _angle;
    	planet = _planet;
    
    	loadGraphic("assets/images/Player.png", true, 16, 16);
    
    	animation.add("Idle", [0, 1], 2, false);
    	animation.add("WalkLeft", [6, 7, 8, 9], 10, false, true);
    	animation.add("WalkRight", [6, 7, 8, 9], 10, false, false);
    
    	FlxG.camera.follow(this);
    }
    
    override public function update(elapsed:Float):Void
    {
    	super.update(elapsed);
    
    	var leftKey = FlxG.keys.anyPressed(["LEFT", "A"]);
    	var rightKey = FlxG.keys.anyPressed(["RIGHT", "D"]);
    	var shootKey = FlxG.keys.anyPressed(["UP", "W", "SPACE"]);
    
    	if (leftKey)
    	{
    		angleFromPlanet -= FlxG.elapsed * speed;
    		animation.play("WalkLeft");
    	}
    	else if (rightKey)
    	{
    		angleFromPlanet += FlxG.elapsed * speed;
    		animation.play("WalkRight");
    	}
    	else
    	{
    		animation.play("Idle");
    	}
    	if (shootKey) {}
    
    	calculatePosition();
    }
    
    function calculatePosition()
    {
    	x = Math.cos(angleFromPlanet - 90 * Math.PI / 180) * (planet.planetRadius - 4 + 8) + planet.getMidpoint().x - 8;
    	y = Math.sin(angleFromPlanet - 90 * Math.PI / 180) * (planet.planetRadius - 4 + 8) + planet.getMidpoint().y - 8;
    
    	angle = FlxAngle.angleBetween(planet, this, true) + 90;
    }
    

    }



  • I tested the class with the image you provided. The idle animation works. I don't know why the animation is not working for you.


Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.