Guest User

Untitled

a guest
Jan 17th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. @interface GameLevelLayer()
  2. {
  3. CCSpriteBatchNode *trexSheet;
  4. int aniCount;
  5. NSTimer *autoWalker;
  6.  
  7.  
  8. }
  9. @end
  10.  
  11. trexSheet = [CCSpriteBatchNode batchNodeWithFile:@"dinosss.png"];
  12. [self addChild:trexSheet];
  13. aniCount=1;
  14.  
  15. -(void)stopWalker{
  16. aniCount =1;
  17. //set to start frame
  18. [self.player setDisplayFrame:
  19. [CCSpriteFrame frameWithTexture:trexSheet.texture rect:
  20. CGRectMake(0,0,32,32)]];
  21.  
  22. if (autoWalker){
  23. [autoWalker invalidate];
  24. autoWalker = nil;
  25. }
  26.  
  27. }
  28.  
  29. -(void)startWalker{
  30.  
  31. if (!autoWalker){
  32. [self walkimate];
  33. //Change the timeInterval to adjust animation speed
  34. autoWalker = [NSTimer scheduledTimerWithTimeInterval:0.15
  35. target:self
  36. selector:@selector(walkimate)
  37. userInfo:nil
  38. repeats:YES];
  39. }
  40. }
  41.  
  42. -(void)walkimate{
  43. ///loop through animation
  44. if (aniCount>4) {
  45. ///set to 0 because we add one at the end before the next call
  46. aniCount =0;
  47. }
  48.  
  49. //this finds the 32x32 pa
  50. [self.player setDisplayFrame:
  51. [CCSpriteFrame frameWithTexture:trexSheet.texture rect:
  52. CGRectMake(32*i,0,32,32)];
  53.  
  54. aniCount++;
  55. }
Add Comment
Please, Sign In to add comment