Advertisement
Guest User

CCAnimation not working, cocos2d

a guest
Sep 23rd, 2012
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. i have two animations declared in the player class, and i want to run then from another class but i can't here's my code:
  2. player.h
  3.  
  4. <code>
  5. @interface Player : CCSprite {
  6. CCAnimate *animationOllie;
  7. CCRepeatForever *repeatNormal;
  8. }
  9. </code>
  10.  
  11. player.m:
  12.  
  13. <code>
  14. @implementation Player
  15.  
  16. -(id)initWithFile:(NSString *)filename
  17. {
  18.     if (self = [super initWithFile:filename]) {
  19.         self.velocity = ccp(0.0, 0.0);
  20.        
  21.        
  22.         CCAnimation *ollie = [CCAnimation animation];
  23.         [ollie setDelayPerUnit:0.05f];
  24.         [ollie addSpriteFrameWithFilename:@"ollie1.png"];
  25.         [ollie addSpriteFrameWithFilename:@"ollie2.png"];
  26.        
  27.         animationOllie = [CCAnimate actionWithAnimation:ollie];
  28.        
  29.        
  30.         CCAnimation *normal = [CCAnimation animation];
  31.         [normal setDelayPerUnit:0.05f];
  32.         [normal addSpriteFrameWithFilename:@"normal1.png"];
  33.         [normal addSpriteFrameWithFilename:@"normal2.png"];
  34.         CCAnimate *animationNormal = [CCAnimate actionWithAnimation:normal];
  35.        
  36.         repeatNormal = [CCRepeatForever actionWithAction:animationNormal];
  37.        
  38.         [self runAction:repeatNormal];
  39.        
  40.     }
  41.     return self;
  42. }
  43. -(void)animateThePlayer {
  44.     [self stopAction:repeatNormal];
  45.     [self runAction:animationOllie];
  46. }
  47.  
  48. </code>
  49.  
  50. And in the GameScene Class:
  51. GameScene.h:
  52.  
  53. @interface GamePlayLayer : CCLayerColor {
  54.     float yVel;
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61. GameScene.m:
  62.  
  63. <code>
  64. #import "Player.h"
  65.  
  66. @interface GamePlayLayer()
  67. {
  68.     Player *player;
  69. }
  70.  
  71. @end
  72.  
  73. @implementation GamePlayLayer
  74.  
  75. -(id) init
  76. {
  77.     if( (self=[super initWithColor:ccc4(255,255,255,255)] )) {
  78.        
  79.         player = [[Player alloc] initWithFile:@"normal1.png"];
  80.  
  81.         [self addChild:player];
  82.        
  83.         self.isTouchEnabled = YES;
  84.        
  85.         player.position = ccp(85,70);
  86.        
  87.        
  88.         [self schedule:@selector(update:)];
  89.        
  90.     }
  91.     return self;
  92. }
  93.  
  94. -(void)update:(ccTime)dt {
  95.  
  96.     if (player.position.y > 70) {
  97.         yVel -= 0.1;
  98.     }
  99.     else {
  100.         if (yVel != 5.5) {
  101.             yVel = 0;
  102.             player.position = ccp(player.position.x, 70);
  103.             //xVel = 0;
  104.         }
  105.     }
  106.     player.position = ccp(player.position.x, player.position.y + yVel);
  107.    
  108. }
  109.  
  110.  
  111. - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  112. yVel = 5.5;
  113.     [player animateThePlayer];
  114. }
  115. </code>
  116.  
  117.  
  118.  
  119.  
  120.  
  121. And that's it, it builds fine, and everything works but when i click the layer it crashes and i get this message:
  122. 0x1df609b:  movl   8(%edx), %edi
  123. Thread 1: EXC_BAD_ACCESS (code=2, address=0xf
  124. What can i do? Thanks in advance
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement