因此,我創建了一個移動基於地圖的牆和圍繞地圖的牆以將玩家保持在操場上的玩家。兩者都有一個物理學的身體。我的猜測是,我的球員運動不合適,所以球員會陷入困境。讓我告訴你我的代碼:SpriteKit:SpriteKit正在相互移動,已經設定了物理體積
所以這是球員的physicsBody:
self.physicsBody!.usesPreciseCollisionDetection = true
self.physicsBody!.categoryBitMask = PhysicsCategory.Player
self.physicsBody!.contactTestBitMask = PhysicsCategory.House
self.physicsBody!.collisionBitMask = PhysicsCategory.Wall
這是華爾街的physicsBody:
self.physicsBody!.usesPreciseCollisionDetection = true
self.physicsBody!.categoryBitMask = PhysicsCategory.Wall
self.physicsBody!.contactTestBitMask = 0
self.physicsBody!.collisionBitMask = PhysicsCategory.Player
self.physicsBody!.isDynamic = false
他們無論是從類繼承對象:
self.physicsBody = SKPhysicsBody(rectangleOf: size)
self.physicsBody!.affectedByGravity = false
self.name = name
所以,只是讓我給你我的代碼如果運動員的運動原因:
func move(direction: String, width: CGFloat){
//Choosing the direction based of the users touch
switch direction{
case "South":
//Decreasing the position of the player by 1 Tile
pos.y -= width
//Flipping the picture the right way to make the player look in the right direction
yScale = 1.0
//Rotates the picture
let rotateAction = SKAction.rotate(toAngle: -1.57, duration: 0.0)
run(rotateAction)
//All the other directions just change the x and y value of pos corresponding to the direction
}
//Moves the player to the calculated position
let moveAction = SKAction.move(to: pos, duration: 0.0)
run(moveAction){
//Sound
}
編輯:
的PhysicsCategory.Player
和PhysicsCategory.Wall
struct PhysicsCategory{
static let Wall:UInt32 = 0x1 << 0
static let Player:UInt32 = 0x1 << 1
static let House:UInt32 = 0x1 << 2
}
編輯2的值:
的主要問題是獲得與SKAction碰撞正常工作
什麼是價值:PhysicsCategory.Player,PhysicsCategory.House和PhysicsCategory.Wall? – Confused
已修改。房子是玩家必須去的目標。同樣的錯誤也發生在那裏。 –
我們需要比我更多的思想。我的困惑。 – Confused