0

我刚开始一个 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:)];
    }
  }
}

}

4

1 回答 1

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..
}

希望这有帮助..谢谢

于 2013-04-05T10:29:09.940 回答