作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
一旦 Sprite 从父级移除,我会尝试调用一个函数,以便 Sprite 可以复制并再次进入场景。
每次我在当前代码中执行此操作时,它都会在原始 Sprite 出现之前进行复制从父项中删除导致重复的 Sprite 。
这是我目前的代码:
import SpriteKit
let plankName = "woodPlank"
class PlankScene: SKScene {
var plankWood : SKSpriteNode?
var plankArray : [SKSpriteNode] = []
override func didMove(to view: SKView) {
plankWood = childNode(withName: plankName) as? SKSpriteNode
let swipeRight : UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(PlankScene.swipedRight))
swipeRight.direction = .right
view.addGestureRecognizer(swipeRight)
}
func swipedRight(sender: UISwipeGestureRecognizer) {
if sender.direction == .right {
let moveOffScreenRight = SKAction.moveTo(x: 400, duration: 0.5)
let nodeFinishedMoving = SKAction.removeFromParent()
plankWood?.run(SKAction.sequence([moveOffScreenRight, nodeFinishedMoving]))
}
//Functions To Be Call After Sequence Finishes
addPlank()
movePlanksUp()
}
func addPlank() {
let newPlank = plankWood?.copy() as! SKSpriteNode
newPlank.position = CGPoint(x: 0, y: -250)
plankArray.append(newPlank)
print(plankArray.count)
addChild(newPlank)
}
func movePlanksUp() {
for node:SKSpriteNode in plankArray {
node.run(SKAction.move(by: CGVector(dx: 0, dy: 250), duration: 0.10))
}
}
}
最佳答案
完成
替换:
plankWood?.run(SKAction.sequence([moveOffScreenRight, nodeFinishedMoving]))
}
//Functions To Be Call After Sequence Finishes
addPlank()
movePlanksUp()
与:
plankWood?.run(SKAction.sequence([moveOffScreenRight, nodeFinishedMoving]),
completion:{
//Functions To Be Call After Sequence Finishes
addPlank()
movePlanksUp()} )
关于ios - SpriteKit : How to call a function within a SKAction. 序列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39987539/
我是一名优秀的程序员,十分优秀!