Swift: 如何在每次触摸屏幕时更改背景的位置?
Swift: How do I change the position of my background every time the screen is touched?
我希望我的背景节点在每次触摸屏幕时向下移动 50 个像素。
编辑:答案:我有两个相同背景的节点,所以背景被包裹起来,每次触摸屏幕时,背景都会向下移动 50 像素。
if bg.position.y + bg.size.height/2 < 50
{
let diff = bg.position.y + bg.size.height/2 - 50
bg.position.y = self.frame.height + bg.size.height/2 + diff
}
else
{
bg.position.y -= 50
}
if bg2.position.y + bg2.size.height/2 < 50
{
let diff = bg2.position.y + bg2.size.height/2 - 50
bg2.position.y = self.frame.height + bg2.size.height/2 + diff
}
else
{
bg2.position.y -= 50
}
更改背景位置?
background.position.y += 50.0
我希望我的背景节点在每次触摸屏幕时向下移动 50 个像素。
编辑:答案:我有两个相同背景的节点,所以背景被包裹起来,每次触摸屏幕时,背景都会向下移动 50 像素。
if bg.position.y + bg.size.height/2 < 50
{
let diff = bg.position.y + bg.size.height/2 - 50
bg.position.y = self.frame.height + bg.size.height/2 + diff
}
else
{
bg.position.y -= 50
}
if bg2.position.y + bg2.size.height/2 < 50
{
let diff = bg2.position.y + bg2.size.height/2 - 50
bg2.position.y = self.frame.height + bg2.size.height/2 + diff
}
else
{
bg2.position.y -= 50
}
更改背景位置?
background.position.y += 50.0