[英]How can I get the real 'self', which node runs the SKaction Sequence
I try to set an extension like SKAction.fireFromEnemy()
, and append to the action sequence, and reuse
the sequence.我尝试设置像
SKAction.fireFromEnemy()
这样的扩展名, SKAction.fireFromEnemy()
加到动作序列, SKAction.fireFromEnemy()
reuse
该序列。 My trouble is I can't get the real self
so I have to set the sequence every time I create the enemy.我的问题是我无法得到真实的
self
所以我每次创建敌人时都必须设置顺序。
Like a SKAction.removeFromParent()
, which func can target the node runs the action.就像
SKAction.removeFromParent()
,哪个 func 可以针对节点运行操作。
SKAction.customAction
is probably what you want. SKAction.customAction
可能就是你想要的。
https://developer.apple.com/documentation/spritekit/skaction/1417745-customaction https://developer.apple.com/documentation/spritekit/skaction/1417745-customaction
Set the duration to 0 if you want it to happen one time.如果您希望它发生一次,请将持续时间设置为 0。
SKAction.customAction(withDuration: 0) { node, time in node.fireFromEnemy() }
Real self
is on closure as a fist parameter of customAction真正的
self
作为 customAction 的第一个参数处于关闭状态
Example:例子:
class TestClass {
init() {
let node = SKSpriteNode(color:.red,size:CGSize(width:100,height:100))
let sequence = SKAction.sequence([.fireFromEnemy, .wait(forDuration: 10), .removeFromParent()])
node.run(sequence)
}
}
extension SKAction {
static let fireFromEnemy = SKAction.customAction(withDuration: 0.3) { node, elapsedTime in
// Do stuff here like:
node.alpha = 0.5
node.zRotation = .pi
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.