【发布时间】:2016-04-27 15:40:11
【问题描述】:
所以本质上,我正在制作一个跳台游戏。当玩家与平台发生碰撞时,玩家会在 y 轴上获得一个向上的冲击力。我得到的下面的代码模拟了玩家跟随的视图。当玩家在 y 轴上向下移动时,它也会跟随玩家。我不想要那个。只希望中景、前景和背景在玩家向上移动时向下移动。
Gamescene.swift:
class GameScene: SKScene, SKPhysicsContactDelegate {
var background:SKNode!
var midground:SKNode!
var foreground:SKNode!
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(size: CGSize){
super.init(size: size)
background = createBackground()
addChild(background)
midground = createMidground()
addChild(midground)
foreground = SKNode()
addChild(foreground)
player = createPlayer()
foreground.addChild(player)
}
override func update(currentTime: CFTimeInterval) {
if player.position.y > 200{
background.position = CGPoint(x: 0, y: -((player.position.y - 200)/10))
midground.position = CGPoint(x: 0, y: -((player.position.y - 200)/4))
foreground.position = CGPoint(x: 0, y: -((player.position.y) - 200))
}
}
【问题讨论】:
标签: ios swift sprite-kit