java - How to set frame of CCSprite -
i have class of character in ccsprite variable. character moving point , animating walking animation after touching button or jumping, works fine, after animation ccsprite has bad frame(one of walking frame). @ end of update function wrote code, frozen, character cant jump or walk more, number of running actions 1:
if(this.sprite.numberofrunningactions() == 0){ if(this.state != characterstate.idle){ this.changestate(characterstate.idle); // without row works still fine } }
changestate function:
public void changestate(characterstate state){ sprite.stopallactions(); this.state = state; switch(state){ case idle:{ this.sprite = ccsprite.sprite(ccspriteframecache.sharedspriteframecache().spriteframebyname("player.png")); break;} case walk_left:{ this.sprite.runaction(waction); break; } . . .
ok, solved alone. :) have created class variable of ccspriteframe type.
ccspriteframe frame_idle;
in class constructor:
frame_idle = ccspriteframecache.sharedspriteframecache().spriteframebyname("player.png");
and case idle have changed to:
case idle:{ this.sprite.setdisplayframe(frame_idle); break; }
Comments
Post a Comment