タッチしたときにゲームをコントロールし、もう一度タッチすると文字が左側に飛びますが、文字が右側に飛んでいれば私は何度も触れ飛行中と、文字が異なる方向に投げ、そして彼は、私はプレイヤーが飛行中にたくさんのタッチでインパルスを取り除く方法(SpriteKit)
enum BodyType: UInt32 {
case playerr = 1
case walll = 2
}
var direction: Direction?
var isInFlight = true
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent? {
if isInFlight == true {
return
} else {
player?.removeAllActions()
switch direction {
case .left:
player?.run(SKAction.moveBy(x: 700, y: 0, duration: 1))
player?.physicsBody?.applyImpulse(CGVector(dx: 700, dy: 500))
direction = .right
case .right:
player?.run(SKAction.moveBy(x: -700, y: 0, duration: 1))
player?.physicsBody?.applyImpulse(CGVector(dx: -700, dy:
500))
direction
}
}
func didBegin(_ contact: SKPhysicsContact) {
let firstBody: SKPhysicsBody
let secondBody: SKPhysicsBody
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {
firstBody = contact.bodyA
secondBody = contact.bodyB
} else {
firstBody = contact.bodyB
secondBody = contact.bodyA
}
if (firstBody.categoryBitMask == BodyType.playerr.rawValue && secondBody.categoryBitMask == BodyType.walll.rawValue) {
print("Add")
isInFlight = false
}
}
func didEnd(_ contact: SKPhysicsContact) {
let firstBody: SKPhysicsBody
let secondBody: SKPhysicsBody
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {
firstBody = contact.bodyA
secondBody = contact.bodyB
} else {
firstBody = contact.bodyB
secondBody = contact.bodyA
}
if (firstBody.categoryBitMask == BodyType.playerr.rawValue && secondBody.categoryBitMask == BodyType.walll.rawValue) {
print("End")
isInFlight = true
}
}
1)コードを共有するために画像を使用することはありません.SOは、人々が使用できるようにフォーマットされたコード用に設計されています。 2)あなたは両方の行動と物理学を行っています。これは本当に両方のエンジンを酷使しています。どちらかを選んで – Knight0fDragon