cocos2d子精灵与父精灵的碰撞检测 [英] cocos2d Children sprite collision detection with parent sprite

查看:192
本文介绍了cocos2d子精灵与父精灵的碰撞检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,stackoverflow社区!



如何在cocos2d中检测到与子精灵碰撞的子sprite碰撞?



目前我有这样的代码:

  CGSize screenSize = [[CCDirector sharedDirector] winSize]; 

parentJumper = [CCSprite spriteWithFile:@inviBtn.png];
jumper = [CCSprite spriteWithFile:@jumperRight.png];

plat = [[Platform alloc] init];

plat = [Platform spriteWithFile:@platformBlack.png];

plat.position = ccp(160,100);

[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 60)];

jumper.anchorPoint = ccp(0.5,0);
jumper.position = ccp(0,20);
parentJumper.position = ccp(screenSize.width / 2,0);

[self addChild:plat];
[self addChild:parentJumper];
[parentJumper addChild:jumper];

现在如何检测 jumper

解决方案

/ div>

通常你可以这样检查冲突:

  if(CGRectIntersectsRect([jumper boundingBox],[plat boundingBox ])){
//处理碰撞< br>
}


Hi stackoverflow community!

How do you detect a children sprite collision with a parent sprite in cocos2d?

Currently I have my codes like this:

    CGSize screenSize = [[CCDirector sharedDirector]winSize];

    parentJumper = [CCSprite spriteWithFile:@"inviBtn.png"];
    jumper = [CCSprite spriteWithFile:@"jumperRight.png"];

    plat = [[Platform alloc]init];

    plat = [Platform spriteWithFile:@"platformBlack.png"];

    plat.position = ccp(160,100);

    [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0/60)];

    jumper.anchorPoint = ccp(0.5, 0);
    jumper.position = ccp(0, 20);
    parentJumper.position = ccp(screenSize.width/2, 0);

    [self addChild:plat];
    [self addChild:parentJumper];
    [parentJumper addChild:jumper];

Now how do I detect the collision between "jumper" & "plat"?

Thanks for your help!

解决方案

Usually you can check collision like this:

if(CGRectIntersectsRect([jumper boundingBox], [plat boundingBox])) {
  //Handle collision<br>
}

这篇关于cocos2d子精灵与父精灵的碰撞检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆