在旧项目中,我创建了类似以下问题的碰撞: 为什么碰撞不起作用,cocos2d v3?. 它运行正常,但是当我创建一个新项目时出现了问题。我不知道这次我做了什么不同的事情。请帮我。
-(void)addAIAction:(int)i{
if (!arrAI) {
arrAI = [[NSMutableArray alloc]init];
}
CCSprite *sprite = [CCSprite spriteWithImageNamed:@"res/gu_button.png"];
sprite.position = [GameConfig convertPoint:ccp(viewSize.width, 160)];
sprite.physicsBody.collisionType=@"aiCollision";
sprite.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:sprite.contentSize.width/2 andCenter:ccp(sprite.contentSize.width/2, sprite.contentSize.height/2)];
sprite.physicsBody.type = CCPhysicsBodyTypeDynamic;
[_physicsNode addChild:sprite];
[arrAI addObject:sprite];
}
//------------------------------------------------ ----------------------
-(void)update:(CCTime)delta{
for (CCSprite *sp in arrPlayer) {
sp.position= ccp(sp.position.x+playerSpeed, sp.position.y);
}
for (CCSprite *sp in arrAI) {
sp.position= ccp(sp.position.x-aiSpeed, sp.position.y);
}
实现委托:
-(BOOL)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair playerCollision:(CCNode *)nodeA aiCollision:(CCNode *)nodeB{
NSLog(@"Coll.");
- (id)init
{
// Apple recommend assigning self with supers return value
self = [super init];
if (!self) return(nil);
viewSize=CGSizeMake([GameConfig converPoint:480], [GameConfig converPoint:320]);
_physicsNode = [CCPhysicsNode node];
_physicsNode.collisionDelegate =self;
_physicsNode.debugDraw =YES;
_physicsNode.gravity=ccp(0, 0);
请让我知道为什么“ccPhysicsCollisionBegin”从不打电话谢谢大家