当 parent 暂停时,是否可以对 child 执行 运行 操作
Is it possible to run action on a child when parent is paused
我想让 child 节点在 parent 暂停时消失。
var plats: SKNode = SKNode();
var bigBox: SKSpriteNode!;
override func didMoveToView(view: SKView) {
// Set anchor point
self.anchorPoint = CGPointMake(0.5, 0.5);
bigBox = SKSpriteNode(color: UIColor.redColor(), size: CGSizeMake(100, 100));
bigBox.zPosition = 1;
plats.addChild(bigBox);
var smallBox: SKSpriteNode = SKSpriteNode(color: UIColor.greenColor(), size: CGSizeMake(50, 50));
smallBox.zPosition = 2;
bigBox.addChild(smallBox);
self.addChild(plats);
}
// 检测到触摸时暂停平台并尝试 运行 child
上的操作
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
// Here I pause the parent
plats.paused = true;
// Get the child node
let smallBox: SKSpriteNode = bigBox.children[0] as! SKSpriteNode;
println(smallBox);
smallBox.paused = false;
println(smallBox.paused); // return false but the action is never trigger
// This part is never run, if I set plats.paused = false it will work but I dont that
let scaleUp = SKAction.scaleTo(0.4, duration: 0.1);
smallBox.runAction(scaleUp, completion: {
self.bigBox.removeAllActions();
self.bigBox.removeFromParent();
println("done");
});
}
这就是所有代码,您可以粘贴并尝试查看它是否有效
xcode版本:6.3
swift版本: 1.2
暂停一个节点后,该节点及其所有后代都将暂停。换句话说,您不能暂停父节点而其子节点之一继续运行。
我想让 child 节点在 parent 暂停时消失。
var plats: SKNode = SKNode();
var bigBox: SKSpriteNode!;
override func didMoveToView(view: SKView) {
// Set anchor point
self.anchorPoint = CGPointMake(0.5, 0.5);
bigBox = SKSpriteNode(color: UIColor.redColor(), size: CGSizeMake(100, 100));
bigBox.zPosition = 1;
plats.addChild(bigBox);
var smallBox: SKSpriteNode = SKSpriteNode(color: UIColor.greenColor(), size: CGSizeMake(50, 50));
smallBox.zPosition = 2;
bigBox.addChild(smallBox);
self.addChild(plats);
}
// 检测到触摸时暂停平台并尝试 运行 child
上的操作override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
// Here I pause the parent
plats.paused = true;
// Get the child node
let smallBox: SKSpriteNode = bigBox.children[0] as! SKSpriteNode;
println(smallBox);
smallBox.paused = false;
println(smallBox.paused); // return false but the action is never trigger
// This part is never run, if I set plats.paused = false it will work but I dont that
let scaleUp = SKAction.scaleTo(0.4, duration: 0.1);
smallBox.runAction(scaleUp, completion: {
self.bigBox.removeAllActions();
self.bigBox.removeFromParent();
println("done");
});
}
这就是所有代码,您可以粘贴并尝试查看它是否有效
xcode版本:6.3 swift版本: 1.2
暂停一个节点后,该节点及其所有后代都将暂停。换句话说,您不能暂停父节点而其子节点之一继续运行。