Swift:每次触摸屏幕时如何更改背景的位置?

时间:2015-01-09 23:41:42

标签: ios swift background sprite-kit

我希望每次触摸屏幕时我的背景节点向下移动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
    }

1 个答案:

答案 0 :(得分:1)

更改背景位置?

background.position.y += 50.0