Need help with Spritemap, animate with play () does not work !?

  • Hello

    I've got stuck with an "Entity & Spritemap" object.
    Can not make it animate with " (" xxx ");
    Have tried ("xxx") in
    Entity new () function, as well as in the update () function.

    I can however animate the object with "sprite.setAnimFrame (" xxx ", index)",
    or with "sprite.frame = index".

     index += 1;
     if (index >= 8)
             index = 5;

    But with " (....)" nothing happens at all.

    What have I missed?
    Have checked
    As far as I can see, I have not done anything differently.

    Sincerely, OB

    here is the full source for my Entity!

    class MushRoom extends Entity 
    	var sprite:Spritemap;
    	var i:Int = 5;	
    	public function new(x:Float=0, y:Float=0) 
    		super(x, y);
    		sprite = new Spritemap("graphics/centipede_8.png", 10, 10);
    		sprite.add("green", [5, 6, 7, 8], 12);"green");
    		//graphic = sprite;
    	public override function update() {
    		/* this works!
    		i += 1;
    		if (i >= 8)
    			i = 5;
    		sprite.frame = i;
                   // or
    		/* this works!
    		i += 1;
    		if (i >= 8)
    			i = 5;
    		sprite.setAnimFrame("green", i);
    		/* this dosen´t work!"green");

  • administrators

    I suspect if you uncomment graphic = sprite and remove addGraphic this will work.

    Graphics and Entities have an active field which determines whether they're updated each frame. By default most graphics are not active (since they have nothing to do) but Spritemap is active by default (since it has to progress the animation.) However, addGraphic puts the Spritemap inside of a Graphiclist, which is not active by default.

    You can also set = true.

    Edit: actually Graphiclist is set to be active automatically if you add any active graphics to it.

  • Hi bendmorris

    I have previously tested with graphic = sprite;
    No difference, displays only the first "frame".
    So I simply have to "force" the animation with sprite.setAnimFrame("green", index) or sprite.frame = index

    And that I just checked if is true,
    And it is actually true.

    Unfortunately, I see no other solution than using. SetAnimFrame () at the moment.

    Sincerely OB

  • administrators

    I'm not sure what the difference might be in your code, but play does work - it's used in the platformer portion of this demo.

  • Hi

    Has created 2 new projects to test the < SpriteMap > again.
    Has basically recreated the code from previous projects.
    Now I get it to work?!?!
    I have compared the code between these projects, just can not see any difference. (there are so few lines, so I just can't see all wrong!? 😉

    Possible that something went wrong in the "Haxedevelop" project files??

    Have compiled to HTML and NEKO, everything now works as intended!

    // OB

  • Hi

    One last word about this.

    If you add public override function update () {...} in your Scene object, then it is Super important to use super.update () in that function.

    Missed this in the beginning when I started a bunch of tests regarding this.
    That's why I didn't get the ("...") to work!

    The same is also true for when you override render () function, add super.render () at the beginning of the function.
    Has also stumbled on that mistake! 😉


Log in to reply

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