[SOLVED] Control Animation Frame from Javascript

So once I have a reference to the affected sprite (such as on a mouse event in javascript), what can I call to change it’s currently shown frame image ?

eg: there is a sprite with 3x frames, and I want to force it to frame 1 when it is already on frame 3, from a javascript code block. I already have the object reference to it, and the javascript documentation shows a setAnimationFrame() function, but it doesn’t appear to work.

eg;
object[0].setAnimationFrame(2);

does not appear to do anything (nor throw an error).

.setAnimationFrame() does work for me.
Maybe it is that you use object[0] instead of objects[0] or the frame number (2) does not exist. Animation is basically an array of images and like all array, the first element is 0, the second is 1, third is 2…etc

Set animation frame of current animation
objects[0].setAnimationFrame(1);

Set animation by number
objects[0].setAnimation(1);

Set animation by name
objects[0].setAnimationName(“animation name”);

1 Like

Huh, that IS working for me now - not sure what i was doing (i wasn’t using object[0] i had another reference name from a for loop elsewhere) but thank you very much! works just fine :slight_smile: