touchesBeganを使用してUIButtonsの機能を提供し、タップジェスチャーを使用してメインプレイヤーSKSpriteNodeがトリガー時にジャンプする機能を提供しました。特定の場所に触れるときにジェスチャーをタップしないようにする - SpriteKit
//コードタップに関するUIButtonタッチ
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
//touches began is only used for GUI buttons -> not to affect player
for touch: AnyObject in touches {
//We get location of the touch
let locationOfTouch = touch.location(in: self)
if muteButton.contains(locationOfTouch) { //mute the game
timer.invalidate()
audioPlayer.volume = 0
}
//コードに関する
let tap = UITapGestureRecognizer(target: self, action: #selector(GameScene.tapped(gesture:)))
tap.cancelsTouchesInView = false
self.view!.addGestureRecognizer(tap)
......
func tapped(gesture: UIGestureRecognizer) { //used to make the player jump
player.physicsBody!.applyImpulse(CGVector(dx: 0, dy: 60))
player.physicsBody!.affectedByGravity = true */
}
私の問題は、私はrestartButtonに押したときにタップジェスチャは、後で活性化されることであるとき、タッチが終了する。何か私にできることはありますか?
別個のタップジェスチャ認識機能を使用する具体的な理由はありますか?ユーザーがボタンに触れないと、プレーヤーがジャンプコードを 'touchesBegan'の中に入れないのはなぜですか? – nathan
私は別のタップジェスチャーを使用しています。これはスライド機能も使用しています。その場合、touchesBeganを使用するとスワイプを識別して認識できません。 –
シーンを再起動するときに、新しいシーンを作成してプレゼンテーションしていますか? – Knight0fDragon