gpt4 book ai didi

swift - 如何在不使用 SKCameraNode 的情况下防止玩家离开屏幕

转载 作者:搜寻专家 更新时间:2023-11-01 07:28:34 27 4
gpt4 key购买 nike

在我的游戏中,我不能真正使用 CameraNode,因为它会搞砸一切的外观和移动方式。我的播放器沿 x 轴移动,我在 update() 函数中设置了这个:

 if player.position.x > 50.0 {

foregroundNode.position = CGPointMake(-(player.position.x - 50), 0)

}

但是,如果点击过多,我的播放器仍然会移出屏幕。我该怎么做才能让它停留在屏幕上,但随着我的播放器向前移动,前景节点仍会向后移动?如有必要,将发布更多代码。

最佳答案

你想做类似的事情

if player.position.x < 50
{
let dx = 50 - player.position.x // if player is at 49, the change is 1
player.position.x = 50
background.position.x += dx // we want to add dx and not subtract because the background moves in the opposite direction of the player
}

关于swift - 如何在不使用 SKCameraNode 的情况下防止玩家离开屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34272724/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com