我有两个SKSpriteKitNodes
,一个在左边,一个在右边。然后我检测触摸位置的位置,并根据其位置进行动作(左侧射击,右侧加速)。但问题是,如果触摸左侧,我怎样才能同时处理右侧触摸?
到目前为止我的代码:
let left = SKSpriteNode()
let right = SKSpriteNode()
override func didMoveToView(view: SKView) {
left.size = CGSize(width: frame.width / 2, height: frame.height)
right.size = CGSize(width: frame.width / 2, height: frame.height)
left.position = CGPoint(x: frame.width / 4, y: frame.height / 2)
right.position = CGPoint(x: 3 * frame.width / 4, y: frame.height / 2)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches{
let location = touch.locationInNode(self)
if right.containsPoint(location){
//HANDLE THE SPEED
if speed == 0{
speed = 5
}
shouldBreak = false
}
if left.containsPoint(location){
//HANDLE THE SHOOTING
shoot.position = CGPoint(x: frame.midX, y: frame.height * 0.2)
isShooting = true
}
}