我正在为“太空侵略者”型射击游戏编写代码,当我通过CGRect
来设置帧时,播放器移至右侧,然后好像整个帧都移至该侧
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch: AnyObject in touches{
let pointOfTouch = touch.location(in: self)
let previousPointOfTouch = touch.previousLocation(in: self)
let amountDragged = pointOfTouch.x - previousPointOfTouch.x
player.position.x += amountDragged
if player.position.x > gameArea.maxX - player.size.width/2 {
player.position.x = gameArea.maxX - player.size.width/2
}
if player.position.x < gameArea.minX + player.size.width/2{
player.position.x = gameArea.minX + player.size.width/2};
}
}