Change animation framerate



  • I still refer to the topdown rpg tutorial: i wanted the player to move faster as Z key is pressed, i've managed to change the speed with an if-else, but i couldn't find a way to increase fps of that animation ( addanimation() loads the animation in memory with fixed fps, I've also checked on the page but i couldn't find anything).

    Is there a way to do so without having to create a new animation that plays faster?

    (Should i delete my old posts in order to keep the HELP section tidy?)


  • administrators

    As you can see in the API docs, FlxAnimation#frameRate is a plain Int variable - no read-only tag, so you should be able to just set it.

    You can use FlxAnimationController's getByName() method to obtain the FlxAnimation instance:

    (Should i delete my old posts in order to keep the HELP section tidy?)

    No! They're a valuable resource for others who browse the forums or google for HaxeFlixel-related issues in the future. :)



  • @Gama11 Thank you! Yes i've seen the frameRate variable but as you guessed i didn't know how to address to a single instance.
    Still i've a problem, probably the synthax i used is wrong, I tried with:

    FlxAnimationController.getByName("up").frameRate = 9;
    

    but i had this error:

    source/Player.hx:96: characters 3-25 : Class<flixel.animation.FlxAnimation> has no field getByName


  • administrators

    FlxAnimationController is the class, and getByName() is an instance field, so it cannot be accessed statically. You can access the FlxAnimationController instance via the animation variable of FlxSprite:

    That means that if you're within the sprite (i.e. a sublcass), animation.getByName() should work. Outside of the sprite, sprite.animation.getByName() would do the trick.

    Btw, this StackOverflow-answer explains the difference between static and instance fields pretty well (in the context of Java, but the concepts are the same).

    In the API docs, static fields have this static tag:

    If that is missing, the field is not static / an instance field.



  • @Gama11 Now everything works as it should.
    Thank you very much for the expanation, it was really useful!


Log in to reply