Jump to content

get certain animation frame?


sinanqd10
 Share

Recommended Posts

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

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

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 spritesheet

you 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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...