Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @interface GameLevelLayer()
- {
- CCSpriteBatchNode *trexSheet;
- int aniCount;
- NSTimer *autoWalker;
- }
- @end
- trexSheet = [CCSpriteBatchNode batchNodeWithFile:@"dinosss.png"];
- [self addChild:trexSheet];
- aniCount=1;
- -(void)stopWalker{
- aniCount =1;
- //set to start frame
- [self.player setDisplayFrame:
- [CCSpriteFrame frameWithTexture:trexSheet.texture rect:
- CGRectMake(0,0,32,32)]];
- if (autoWalker){
- [autoWalker invalidate];
- autoWalker = nil;
- }
- }
- -(void)startWalker{
- if (!autoWalker){
- [self walkimate];
- //Change the timeInterval to adjust animation speed
- autoWalker = [NSTimer scheduledTimerWithTimeInterval:0.15
- target:self
- selector:@selector(walkimate)
- userInfo:nil
- repeats:YES];
- }
- }
- -(void)walkimate{
- ///loop through animation
- if (aniCount>4) {
- ///set to 0 because we add one at the end before the next call
- aniCount =0;
- }
- //this finds the 32x32 pa
- [self.player setDisplayFrame:
- [CCSpriteFrame frameWithTexture:trexSheet.texture rect:
- CGRectMake(32*i,0,32,32)];
- aniCount++;
- }
Add Comment
Please, Sign In to add comment