gpt4 book ai didi

ios - 边界功能不会阻止 Sprite 离开

转载 作者:行者123 更新时间:2023-11-29 01:21:12 27 4
gpt4 key购买 nike

首先你应该知道,允许玩家玩的区域是一个正方形,即320x320,位于屏幕中央。这个 320x320 的正方形是一个 5x5 的网格 [每个图 block 64x64],并且玩家始终位于网格图 block 的中心。

当玩家移动时,无论方向如何,它始终是 64 像素移动。[网格大小的 1/5]。

func move(node: SKSpriteNode, direction: String) {
//'node' determines what spritekitnode to move.
//'direction' classifies which statement to run.
if node.name == "player" {
if direction == "left" {
if node.position.x - 64 >= map.position.x - 160 {
//Checks if the Node can move without
//moving off the grid [map, the 5x5 grid].
node.runAction(moveLeft)
//Moves the Node
}
}
if direction == "right" {
if node.position.x + 64 <= map.position.x + 160 {
node.runAction(moveRight)
}
}
if direction == "up" {
if node.position.y + 64 <= map.position.y + 160 {
node.runAction(moveUp)
}
}
if direction == "down" {
if node.position.y - 64 >= map.position.y - 160 {
node.runAction(moveDown)
}
}
if direction == nil {
print("[move() function] : No direction specified!")
}
}


}

我的问题是当玩家发送垃圾邮件或快速按下按钮多次移动时连续地,玩家最终能够离开网格。

例如,当玩家位于 5x5 网格的底部图 block 上并以 2 倍的速度向下移动时足够了,玩家离开网格。

最佳答案

这是因为 RunAction 不会删除之前的操作,所以当它们发送垃圾邮件时,它们会将多个操作排队并发运行。您需要让移动函数不允许边界被打破,或者在运行新操作之前调用 removeAllActions

关于ios - 边界功能不会阻止 Sprite 离开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34583963/

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