抱歉重新打开这个标题,但这个问题的标题都没有给我带来太多帮助。在我的游戏中你是一艘太空飞船,你试图逃离传入的小行星。当你的船接触到一颗小行星时,你就会爆炸。 我的代码就像这些;
static const uint32_t asteroidCategory = 1;
static const uint32_t playerCategory = 2;
static const uint32_t laserCategory = 3;
player.physicsBody.categoryBitMask = playerCategory;
player.physicsBody.contactTestBitMask = asteroidCategory;
player.physicsBody.collisionBitMask = 0;
asteroid.physicsBody.categoryBitMask=asteroidCategory;
asteroid.physicsBody.contactTestBitMask=playerCategory;
asteroid.physicsBody.collisionBitMask=0;
但我不知道我应该在'didBeginContact'方法做什么。 请帮帮我,谢谢...
答案 0 :(得分:0)
尝试从
开始-(void)didBeginContact:(SKPhysicsContact *)contact
{
SKPhysicsBody *firstBody, *secondBody;
if (contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask)
{
firstBody = contact.bodyA;
secondBody = contact.bodyB;
}
else
{
firstBody = contact.bodyB;
secondBody = contact.bodyA;
}
if ((firstBody.categoryBitMask & playerCategory) != 0 &&
(secondBody.categoryBitMask & astroidCategory) != 0)
{
[self player:(SKSpriteNode *) firstBody.node didCollideWithAstroid:(SKSpriteNode *) secondBody.node];
}
你还需要为'didCollideWithAstroid'
制作一个方法