mraak Posted June 2, 2014 Share Posted June 2, 2014 Can I play the animation starting from random frame, and then loop? Say I have 20 frames. I want to start from 8th, continuing to 20, and then loop from 1st all the way to 20th and so on. This doesn't seem to do anything:animations.frame = 8;animations.play("all"); Link to comment Share on other sites More sharing options...
wayfinder Posted June 2, 2014 Share Posted June 2, 2014 try play first and then setting the frame Link to comment Share on other sites More sharing options...
mraak Posted June 2, 2014 Author Share Posted June 2, 2014 Nope, nothing. Link to comment Share on other sites More sharing options...
wayfinder Posted June 3, 2014 Share Posted June 3, 2014 Does it work if you use setFrame(8) instead of animation.frame=8? Do you need the animation to always start from the same frame? You could create it starting from there with animations.add('all', [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2, 3, 4, 5, 6, 7], fps, true); LUVS2SPWG 1 Link to comment Share on other sites More sharing options...
mraak Posted June 3, 2014 Author Share Posted June 3, 2014 No it should start from arbitrary frame. I was thinking of constructing 20 arrays but it seems like an overkill. And setFrame throws an error like the function isn't even therehero.animations.setFrame( _.random(0,45));Uncaught TypeError: undefined is not a function Link to comment Share on other sites More sharing options...
wayfinder Posted June 3, 2014 Share Posted June 3, 2014 I think you need to call setFrame on the animation maybe? hero.animations.currentAnim.setFrame(8); webcaetano and jjwallace 1 1 Link to comment Share on other sites More sharing options...
mraak Posted June 3, 2014 Author Share Posted June 3, 2014 What finally worked is using your approach AND setting the second parameter to true. hero.animations.play("fall");hero.animations.currentAnim.setFrame(8, true);useLocalFrameIndex = true, works but I don't know what it means exactly. Thanks. jjwallace, ozdy, Raheel and 1 other 3 1 Link to comment Share on other sites More sharing options...
webcaetano Posted January 27, 2016 Share Posted January 27, 2016 Nice question, nice answer. Link to comment Share on other sites More sharing options...
jjwallace Posted June 30, 2018 Share Posted June 30, 2018 I cannot figure it out, how did you get it to work? I get an error, setFrame is not a function. And then if i default.setFrame it says cannot read setframe of undefined Phaser.Sprite.call(this, game, getRandom(0, game.world.width), getRandom(0, game.world.height), 'spJellyFish'); this.animations.add('default'); this.animations.play('default', 30, true); this.animations.setFrame(getRandom(0, 20), true); Link to comment Share on other sites More sharing options...
Recommended Posts