我正在开发一个带球和一些酒吧的游戏。我在游戏层中将球创建为ccsprite,将条形图创建为节点。问题是cocos2d似乎无法检测到球和杆之间的碰撞。这是我使用的代码。这是gameplayer.m。
-(id)init{
if((self= [super init])){
CGSize winSize = [[CCDirector sharedDirector]winSize];
self.isTouchEnabled = YES;
ball = [CCSprite spriteWithFile:@"redball final.png"];
ball.position = ccp(150,300);
[self addChild:ball z:1];
barOne = [Bar node];
[self addchild:barOne];
moveAction = [CCMoveTo actionWithDuration:5 position:ccp(barOne.position.x,-winSize.height)];
[barOne runAction:moveAction];
[self addChild:barOne];
[self schedule:@selector(update:)];
}
return self;
}
-(void) update:(ccTime)dt
{
if (CGRectIntersectsRect(ball.boundingBox,barOne.boundingBox))
{
[self removeChild:ball];
}
}