//Adding SpriteKit physicsBody for collision detection
missile.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:missile.size];
missile.physicsBody.categoryBitMask = obstacleCategory;
missile.physicsBody.dynamic = YES;
missile.physicsBody.contactTestBitMask = shipCategory;
missile.physicsBody.collisionBitMask = 0;
missile.physicsBody.usesPreciseCollisionDetection = YES;
missile.name = @"missile";
碰撞相关的解释如下
bird.physicsBody?.allowsRotation = false //禁止旋转
bird.physicsBody?.categoryBitMask = birdCategory //设置小鸟物理体标示
bird.physicsBody?.contactTestBitMask = floorCategory | pipeCategory //设置可以小鸟碰撞检测的物理体
CollisionBitmask:确定两个物体是否允许碰撞
如果希望A和B允许碰撞,则
A的CategoryBitmask与B的CollisionBitmask与运算结果为0
B的CategoryBitmask与A的CollisionBitmask与运算结果为0
否则A和B就不允许碰撞,接触后直接弹开
如果希望A和B发生碰撞检测,即调用onContactBegin,则
A的CategoryBitmask与B的ContactTestBitmask与运算结果不为0
B的CategoryBitmask与A的ContactTestBitmask与运算结果不为0
usesPreciseCollisionDetection一个布尔值,确定物理世界使用一个迭代的碰撞检测算法。
收缩.gif
entrance.gif
entracenImage.png
网友评论