【问题标题】:how to apply animation for CCSprite如何为 CCSprite 应用动画
【发布时间】:2013-04-05 10:11:10
【问题描述】:

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

}

【问题讨论】:

  • 你检查过每一行代码都被执行了吗?
  • 是的。我放了断点并检查了它。

标签: iphone cocos2d-iphone game-physics ccsprite


【解决方案1】:

试试这个,

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

希望这会有所帮助.. 谢谢

【讨论】:

  • 在我身边正常工作,伙计。尝试在未安排评论的情况下运行。
  • @HaveToLearnMore 这与您正在做的不同。显示 spriteDone 的代码 ...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-23
  • 2014-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多