gpt4 book ai didi

swift - parent 暂停时是否可以对 child 执行操作

转载 作者:行者123 更新时间:2023-11-28 09:09:32 26 4
gpt4 key购买 nike

我想让子节点在父节点暂停时消失。

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快速版本:1.2

最佳答案

一旦您暂停一个节点,该节点及其所有后代都将暂停。换句话说,您不能暂停父节点而其子节点之一继续运行。

关于swift - parent 暂停时是否可以对 child 执行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29714127/

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