我的游戏中有三个节点 -
玩家-
这是一艘可以使用操纵杆拖动的船。
let collisionPlayer : UInt32 = 0x1 << 1
let apple = SKSpriteNode(texture: texture)
apple.position = position
apple.physicsBody = SKPhysicsBody(circleOfRadius: apple.size.width / 2.0)
apple.physicsBody?.affectedByGravity = false
apple.physicsBody?.isDynamic = true
apple.setScale(0.1)
addChild(apple)
Run Code Online (Sandbox Code Playgroud)
(“苹果”是船)
敌船——
这是一艘随机跟随玩家的 CPU 船。
let collisionNPC : UInt32 = 0x1 << 0
appleNPC.position = position
appleNPC.physicsBody = SKPhysicsBody(circleOfRadius: appleNPC.size.width / 2.0)
appleNPC.physicsBody?.isDynamic = true
appleNPC.physicsBody?.affectedByGravity = false
appleNPC.position = CGPoint(x: 600, y: 200)
appleNPC.setScale(0.1)
addChild(appleNPC)
Run Code Online (Sandbox Code Playgroud)
子弹 (不言自明)
let collisionBullet : UInt32 = 0x1 …Run Code Online (Sandbox Code Playgroud)