3d TouchのデバイスでxCodeレベルエディタを使用するためのカスタムSKSpriteNodeボタンの取得に問題があります。SpriteKit Xcodeレベルエディタカスタムボタンクラスのタッチイベントなし(3Dタッチ)
私はほとんどがAppleのDemoBotsサンプルに基づいているボタンサブクラスを持っています。
基本的なコードは、私はXcodeのレベルエディタを経由してボタンを作成する場合は、テスト飛行を使用した場合、すべてが6Sと私の友人が、シミュレータや私のiPhone 6に正常に動作しているこの
enum ButtonIdentifier: String {
case playButton
case pauseButton
}
/// Button responder delegate
protocol ButtonDelegate: class {
func pressed(button button: ButtonNode)
}
class ButtonNode: SKSpriteNode {
public weak var delegate: ButtonDelegate? {
return scene as? ButtonDelegate
}
var isHighlighted = false {
didSet {
// running skactions to colorise buttons and animate
}
}
var identifier: ButtonIdentifier!
/// Code init (when button is created in code)
/// e.g let playButton = ButtonNode(imageNamed: "ButtonImage", identifier: playButton)
init(imageNamed: String, identifier: ButtonIdentifier) {
self.identifier = identifier
let texture = SKTexture(imageNamed: imageNamed)
super.init(texture: texture, color: SKColor.clearColor(), size: texture.size())
name = identifier.rawValue
setup()
}
/// Level editor init (when button is created in level editor)
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
// Ensure that the node has a supported button identifier as its name.
guard let nodeName = name, identifier = ButtonIdentifier(rawValue: nodeName) else {
fatalError("Unsupported button name found.")
}
self.identifier = identifier
setup()
}
private func setup() {
// zPosition
zPosition = 200
// Enable user interaction on the button node to detect tap and click events.
userInteractionEnabled = true
}
#if os(iOS)
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event)
isHighlighted = true
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesEnded(touches, withEvent: event)
guard let scene = scene else { return }
for touch in touches {
let location = touch.locationInNode(scene)
let node = scene.nodeAtPoint(location)
if node === self || node.inParentHierarchy(self) {
runPressedAction()
} else {
isHighlighted = false
}
}
}
override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
super.touchesCancelled(touches, withEvent: event)
isHighlighted = false
}
#endif
// MARK: - Pressed Action
private func runPressedAction() {
// SKAction that runs a press animation
delegate?.pressed(button: self)
}
}
だろうプラスはボタンにタッチ入力を得ず、彼はそれらを押すことができません。
コード内にボタンをすべて作成すると、3Dタッチデバイスでもすべてが機能します。
3Dタッチデバイスのレベルエディタのボタンでは機能しないのはなぜですか?私はいくつかの設定や何かを見逃しているかどうかを確認するためにリンゴデモボットのサンプルを見ようとしていますが、私はそれを理解することはできません。 (デモのボットボタンは私の友人のiPhone 6s plusで動作します)
3Dタッチデバイスでは、x/y座標に変更がなくてもtouchesMovedメソッドが呼び出されます。しかし、私はこれが私の問題を引き起こすとは思わない。なぜなら、コード内にボタンを作成すると、すべてが期待通りに機能するからです。
3Dタッチデバイスのタッチを許可するためにXcodeレベルエディタに設定がありますか?
なぜ関係のないコードを表示し、実際にタッチイベントを含むコードを表示しますか? – Knight0fDragon
私は自分の答えを1分更新します。主な理由は、コードで作成した場合、3Dタッチデバイスで完全に機能するということです。 Xcodeのレベルエディタを使用しているときに動作しません。 – crashoverride777
その部分も見せてください(コードにシーンを追加する方法) – Knight0fDragon