ありがとうございます。私はジェスチャーレコグナイザーを使用しており、私はSKSpriteNodeテクスチャを左右にスワイプして変更します。選択/選択解除されたボタンの効果が得られます。単なるbool型の変数buttonSelectedを使うだけで、ボタンのテクスチャが変更されるたびに更新します。この変数を使用して、リモートをクリックした後に実行するアクションを決定します。これは、buttonAction関数の単純なif文で行われます。これがあなたに役立つことを願っています。私はまだ非常に迅速なので、私はそれを明確に記述して願っています。
class GameScene: SKScene {
var button = SKSpriteNode(imageNamed: "button.png")
var buttonSelected = false
var button2 = SKSpriteNode(imageNamed: "button2.png")
var button2Selected = false
override func didMoveToView(view: SKView) {
button.position = CGPoint(x: 900, y:100)
self.addChild(button)
button2.position = CGPoint(x: 1700, y:100)
self.addChild(button2)
// gesture recognizer
let swipeRight:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(GameOverScene.swipedRight(_:)))
swipeRight.direction = .Right
view.addGestureRecognizer(swipeRight)
let swipeLeft:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(GameOverScene.swipedLeft(_:)))
swipeLeft.direction = .Left
view.addGestureRecognizer(swipeLeft)
let tapGeneralSelection = UITapGestureRecognizer()
tapGeneralSelection.addTarget(self, action: #selector(GameScene.buttonAction))
tapGeneralSelection.allowedPressTypes = [NSNumber (integer: UIPressType.Select.rawValue)]
self.view!.addGestureRecognizer(tapGeneralSelection)
}
func swipedRight(sender:UISwipeGestureRecognizer){
let buttonTexture1 = SKTexture(imageNamed: "button2Selected.png")
button2.runAction(SKAction.setTexture(buttonTexture1))
button2Selected = true
let buttonTexture2 = SKTexture(imageNamed: "button.png")
button.runAction(SKAction.setTexture(buttonTexture2))
buttonSelected = false
}
func swipedLeft(sender:UISwipeGestureRecognizer){
let buttonTexture1 = SKTexture(imageNamed: "buttonSelected.png")
button.runAction(SKAction.setTexture(buttonTexture1))
buttonSelected = true
let buttonTexture2 = SKTexture(imageNamed: "button2.png")
button2.runAction(SKAction.setTexture(buttonTexture2))
button2Selected = false
}
func buttonAction() {
if(buttonSelected == true) {
// do something after button is pressed
} else if (button2Selected == true) {
// do something after button2 is pressed
}
}
}