ios - 如何从数组中移动单个 SKspritenode
问题描述
我有一个精灵数组,点击它时移动它,问题是它正在移动所有精灵,我希望它移动单个元素,我该怎么做?先感谢您
这是我的代码:
var containerPieces: [ContainerPieces] = []
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
let rsCurrent = self.atPoint(location)
for nodo in containerPieces {
let rsBody = nodo.block.physicsBody
if rsBody == rsCurrent.physicsBody {
if nodo.block.frame.contains(location) {
nodo.block.position = location
nodo.block.run(blinkAnimation(), withKey:"wiggle")
isFingerOnPaddle = true
}
}
}
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
if isFingerOnPaddle {
let touch = touches.first
let touchLocation = touch!.location(in: self)
let previousLocation = touch!.previousLocation(in: self)
for nodo in containerPieces{
var paddleX = nodo.block.position.x + (touchLocation.x - previousLocation.x)
var paddleY = nodo.block.position.y + (touchLocation.y - previousLocation.y)
paddleX = max(paddleX, nodo.block.size.width/2)
paddleX = min(paddleX, size.width - nodo.block.size.width/2)
paddleY = max(paddleY, nodo.block.size.width/2)
paddleY = min(paddleY, size.width - nodo.block.size.width/2)
nodo.block.position = CGPoint(x: paddleX, y: paddleY)
}
}
}
解决方案
推荐阅读
- laravel - Laravel Left join 多个表并返回原始表值
- angular - 中间带有 IF 语句的 RxJS 管道链接
- mysql - 为什么phpMyAdmin说主键和UNIQUE约束都是索引?
- symfony - fos 用户的登录显示
- visual-c++ - 关于 WTSInfoExLevel 的一些问题
- java - JAVA - 拆分包含分隔符的字符串#| . 如果 #| 多次出现,字符串也应该拆分。喜欢 - #|#|
- docker - 使用 ecs 部署时在 docker 日志中获取 t msg="Container ****** failed to exit within 10 seconds of signal 15 - using the force"
- wordpress - WordPress网站随机间隔慢
- pyqt5 - QDarkStyle - 如何修改小部件属性?
- java - 使用单个侦听器检查多个元素