sinanqd10 Posted October 28, 2014 Share Posted October 28, 2014 var loop;var playingGroup;function preload() { game.load.spritesheet('rpsLeft','assets/rps-left.png',92,86);}function dynamicSprite(x,key) { loop = game.add.sprite(x,game.world.centerY- 35,key); loop.animations.add('play',[0, 1, 2]); loop.animations.play('play',20,true); loop.smoothed = false; playingGroup.create(loop);}btn = game.add.button(game.world.centerX - 70,game.world.centerY + 105,'rockSprite',this.btnRock,this,1,0,2,0);btn.input.useHandCursor = true;function btnRock() {//here..}How can i get the certain spritesheet frame when I click the buttonRock? Link to comment Share on other sites More sharing options...
sinanqd10 Posted October 28, 2014 Author Share Posted October 28, 2014 Now I have figure out the solutionfunction btnRock() {loop.animations.stop(null,true); loop.animations.frame = 0;} Link to comment Share on other sites More sharing options...
valueerror Posted October 28, 2014 Share Posted October 28, 2014 this should fetch the frame that is displayed right now currentframe = loop.frameName; Link to comment Share on other sites More sharing options...
sinanqd10 Posted October 28, 2014 Author Share Posted October 28, 2014 Thanks you valueerror for your answered,but I didn't get your point. Can you please kindly clarify.The thing that I wanted is that get the specific frame to set the Rock image when clicking the button rock.The code here is working fine. However, it seems not running smoothly.function btnRock() { loop.animations.stop(null,true); loop.animations.frame = 0;} Link to comment Share on other sites More sharing options...
valueerror Posted October 28, 2014 Share Posted October 28, 2014 oh sorry.. i thought you want to get the current frame of the animation that loops at the moment.. you actually want to SET (not get) a specific frame on click on the button.. that should be easy too:loop.frame=0; //sets the sprite to frame 0 of it's spritesheetyou dont set the animation.frame because the animation just stopped.. so no animation is ongoing anymore.. just set the frame of the sprite directly Link to comment Share on other sites More sharing options...
sinanqd10 Posted October 29, 2014 Author Share Posted October 29, 2014 Thanks Valueerror for answered. but, when I set the the frame directly, the animation doesn't stop. Anyway, thanks you Link to comment Share on other sites More sharing options...
valueerror Posted October 29, 2014 Share Posted October 29, 2014 i did NOT say the animation would stop automatically by setting sprite.frame i tried to say that at the specific line in your own code where you currently call "loop.animation.frame" your animation is (should be) already stopped... therefore you can just set a new sprite.frame - that's all "loop.animations.stop(null,true);" (or just "loop.animations.stop()" as seen in your code stops the animation.. then set the frame you want. if this does not work.. provide a working demo in a zip file and i'll have a look why Link to comment Share on other sites More sharing options...
sinanqd10 Posted October 30, 2014 Author Share Posted October 30, 2014 Hehehe, its working now valueerror. However I got one more problem with button reset and play again.Here is the flash site Rock Paper Scissors http://www.happymeal.com.au/en_AU/index.html#/Home.click the games menu and scroll to find out the game RPS. can u show me the tricks Link to comment Share on other sites More sharing options...
Recommended Posts