Swift Sprite节点碰撞

时间:2017-06-29 23:58:50

标签: swift xcode sprite-kit skspritenode

我想让两个SKSpriteNodes互相传递。根据我的理解,以下代码应该可以解决问题:

        beam?.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: beam!.size.width - 40, height: beam!.size.height/4));
        beam?.physicsBody?.categoryBitMask = ColliderType.BEAM;
        beam?.physicsBody?.contactTestBitMask = ColliderType.ENEMY;
        beam?.physicsBody?.collisionBitMask = 0;
        beam?.physicsBody?.affectedByGravity = false;
        beam?.physicsBody?.allowsRotation = false;

        item?.physicsBody?.categoryBitMask = ColliderType.CRATES;
        item?.physicsBody?.contactTestBitMask = ColliderType.PLAYER;
        item?.physicsBody?.collisionBitMask = ColliderType.GROUND;            
        item?.physicsBody?.affectedByGravity = true;
        item?.physicsBody?.allowsRotation = false;

因为它们都不应被其他对手的类型所吸引。我已经尝试了很多不同的方法,包括将它们的碰撞位掩码设置为0.

当两个节点碰撞时,物品移动到梁下方。然后当光束消失时,物品移回原来的位置。该项必须保持动态到其他节点,但非常感谢有关此主题的建议。感谢。

struct ColliderType {
static let PLAYER: UInt32 = 0;
static let GROUND: UInt32 = 1;
static let CRATES: UInt32 = 2;
static let BULLET: UInt32 = 3;
static let ENEMY: UInt32 = 4;
static let EXPLOSION: UInt32 = 5;
static let UFO: UInt32 = 6;
static let UFOBOMB: UInt32 = 7;
static let SHIELD: UInt32 = 8;
static let BEAM: UInt32 = 9;
}

0 个答案:

没有答案