我正在尝试检查两个物体的碰撞碰撞,但碰撞检测回调没有被触发.这是我的代码:
I'm trying to inspect collision collision of two bodies, but collision detection callbacks are not being fired. Here is my code:
1) 我的 CCScene 实现了 CCPhysicsCollisionDelegate 协议
1) My CCScene implements CCPhysicsCollisionDelegate protocol
2) 我为物理设置碰撞委托
2) I set collision delegate for physics
_physics = [CCPhysicsNode node];
_physics.gravity = PHYSICS_GRAVITY;
_physics.debugDraw = YES;
_physics.collisionDelegate = self;
[self addChild:_physics];
3) 我为两个身体中的每一个设置一个碰撞类型
3) For each of two body I set a collision type
body1.collisionType = @"body1";
body2.collisionType = @"body2";
4) 就是这样,当这两个物体发生碰撞时,不会调用任何 CCPhysicsCollisionDelegate 回调方法.
4) That's it, when these two bodies collide none of CCPhysicsCollisionDelegate callback methods is being called.
- (BOOL)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair typeA:(CCNode *)nodeA typeB:(CCNode *)nodeB
{
NSLog(@"HELLO");
return YES;
}
你能帮我解决这个问题吗?你在 cocos2d v3 中能接收到碰撞回调吗?
Could you please help me with this? Have you been able to receive collision callbacks in cocos2d v3?
提前致谢
推荐答案
在 cocos2d v3 物理中,collisionType
消除了设置整数位掩码来定义碰撞类型的需要.CCPhysicsCollisionDelegate
方法的参数名称必须是您要自己处理的碰撞类型.所以在你的情况下,碰撞回调方法应该是
In cocos2d v3 physics, collisionType
eliminates the need to set integer bit masks to define the type of collision. The parameter name CCPhysicsCollisionDelegate
methods must be the collisionTypes that you want to deal with yourself. So in your case , the collision callback method should be
- (BOOL)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair body1:(CCNode *)nodeA body2:(CCNode *)nodeB
{
NSLog(@"HELLO");
return YES;
}
cocos2d 中默认一切都会发生碰撞,但是如果你将两个 body 的 collisionGroup
设置为相同,那么它们就不会发生碰撞.
By default everything collides in cocos2d, but if you set the collisionGroup
of two bodies to be the same then they wouldn't collide.
相关推荐
最新文章