相关疑难解决方法(0)

Cocos2d游戏中的碰撞检测?

我试图通过以下方式检测两个精灵的碰撞 ...但是当我尝试运行游戏时没有发生碰撞......我可能做错了什么?

- (void)update:(ccTime)dt {



    CGRect projectileRect = CGRectMake(projectile.position.x - (projectile.contentSize.width/2), 
                                       projectile.position.y - (projectile.contentSize.height/2), 
                                       projectile.contentSize.width, 
                                       projectile.contentSize.height);

    //CGRectMake(0,220,320,50);
    CGRect targetRects =  CGRectMake(_monkey.position.x - (_monkey.contentSize.width/2), 
                                 _monkey.position.y - (_monkey.contentSize.height/2), 
                                 _monkey.contentSize.width, 
                                 _monkey.contentSize.height);

        if (CGRectIntersectsRect(projectileRect, targetRects)) {
                    NSLog(@"ha ha Collision detected"); 
        }                       
Run Code Online (Sandbox Code Playgroud)

}

射弹精灵从屏幕顶部到底部动画,猴子精灵在底部动画从底部向右射弹穿过猴子,但日志不会被称为???

- (void)update:(ccTime)dt {

CGRect projectileRect = [projectile boundingBox];
CGRect targetRects = [_monkey boundingBox];

if (CGRectIntersectsRect(projectileRect, targetRects))
{
    NSLog(@"ha ha Collision detected");
}

CGRect projectileRects = CGRectMake(projectile.position.x - (projectile.contentSize.width/2), 
                                   projectile.position.y - (projectile.contentSize.height/2), 
                                   projectile.contentSize.width, 
                                  projectile.contentSize.height);
CGRect targetRect = …
Run Code Online (Sandbox Code Playgroud)

iphone cocos2d-iphone ios4

6
推荐指数
1
解决办法
8072
查看次数

标签 统计

cocos2d-iphone ×1

ios4 ×1

iphone ×1