【发布时间】:2012-07-05 07:51:57
【问题描述】:
你好 stackoverflow 社区!
如何在 cocos2d 中检测子精灵与父精灵的碰撞?
目前我有这样的代码:
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”和“plat”之间的碰撞?
感谢您的帮助!
【问题讨论】:
-
首先,为什么你初始化你的平台两次?你会在这里得到内存泄漏。第二个你可以将比较精灵的矩形坐标转换为世界坐标,然后比较它们
标签: cocos2d-iphone parent collision-detection sprite