我的屏幕上有一个用陀螺仪移动的节点。但是我不能将它的位置限制在屏幕上,我已经尝试过了,但是它只适用于底部和顶部:
override func update(currentTime: CFTimeInterval){
...
if sprite.position.x <= sprite.frame.width / 2 {
print("out on the left of the screen")
}
if sprite.position.x >= self.frame.width - sprite.frame.width / 2 {
print("out on the right of the screen")
}
if sprite.position.y <= sprite.frame.height / 2 {
print("out on the top of the screen")
//worked
}
if sprite.position.y <= self.frame.height - sprite.frame.height / 2 {
print("out on the bottom of the screen")
//worked
}
}