如何为CCSprite应用动画

时间:2013-04-05 10:11:11

标签: iphone cocos2d-iphone game-physics ccsprite

我刚开始一个cocos2d游戏。在那里检查碰撞,如果碰撞发生使用以下代码创建动画。动画代码被调用但没有显示任何动画。这是什么错误。请帮我解决

-(void)check_collision:(ccTime)dt
{
  for(PolygonSprite *sprite in _cache)
  {
    if(CGRectIntersectsRect(sprite.boundingBox,monkey.boundingBox))
    {
      if(sprite != monkey)
      {
      NSLog(@"collision collision collision.......%@",sprite);
      id s2 = [CCScaleTo actionWithDuration:0.5 scaleX:1.5 scaleY:1.5];
      id fun = [CCCallFuncN actionWithTarget:self selector:@selector(spriteDone:)];
      [sprite runAction:[CCSequence actions:s2,fun,nil]];
      [self unschedule:@selector(check_collision:)];
    }
  }
}

}

1 个答案:

答案 0 :(得分:0)

试试这个,

[self schedule:@selector(check_collision:)interval:1];

-(void) check_collision: (ccTime) t
{
   for(PolygonSprite *sprite in _cache)
   {
       if(CGRectIntersectsRect(sprite.boundingBox,monkey.boundingBox))
       {
           if(sprite != monkey)
           {
               id s2 = [CCScaleTo actionWithDuration:0.1 scaleX:2 scaleY:2];
               id fun = [CCCallFuncN actionWithTarget:self  selector:@selector(spriteDone)];
               [car.sprite runAction:[CCSequence actions:s2,fun,nil]];
               [self unschedule:@selector(check_collision:)];
           }
       }
    }
}

-(void) spriteDone
{
    // Function logic goes here..
}

希望这有帮助..谢谢