【问题标题】:how to avoid SKNode's blink when i remove a moving node?移除移动节点时如何避免 SKNode 闪烁?
【发布时间】:2017-08-28 10:43:53
【问题描述】:

我正在玩一个小游戏,我的节点是这样移动的:

    SKAction * actionMove = [SKAction moveToY:HEIGHT + self.frame.size.height / 2 duration:actualDuration];
[self runAction:[SKAction sequence:@[actionMove, loseAction]] withKey:@"start"];

我从另一个角度驳回它,它只是这样称呼:

- (void)dissmissBubbleWithType:(BubbleType)type{
__block BOOL isDismiss = NO;
NSString *name = [[ResManager sharedManager] nameFromBubbleType:type];
[self enumerateChildNodesWithName:name usingBlock:^(SKNode * _Nonnull node, BOOL * _Nonnull stop) {
    BubbleNode *bubbleNode = (BubbleNode *)node;
    isDismiss = YES;
    [bubbleNode cracked];
}];
if (isDismiss) {
    [self.bubbleDelegate dismissBubbleWithType:type];
}

}

当我解雇一个类型时,我使用 enumerateChildNodesWithName usingBlock 删除我的节点;

这是bubbleNode破解的,我用它来播放gif并删除它;

- (void)cracked{
self.name = @"cracked";
[self removeAllActions];
SKAction * actionMoveDone = [SKAction animateWithTextures:[ResManager sharedManager].bubbleCrackArray timePerFrame:0.2];
SKAction *done = [SKAction removeFromParent];
[self runAction:[SKAction sequence:@[actionMoveDone,done]]];

}

现在的问题是,当我调用 dissmissBubbleWithType 时,节点会闪烁到较旧的位置。 我认为原因是当我调用 dissmissBubbleWithType 和 enumerateChildNodesWithName:name 时,节点的 position.y 是 100,但在它删除时,position.y 是 90(因为它正在移动)。 我尝试了某种方式,例如 1.removeAllActions 然后播放 gif 2.removeFromParent 不播放 gif 3.在scene.children中使用foreach 但它仍然闪烁

所以请帮帮我,非常感谢:)

【问题讨论】:

    标签: ios objective-c sprite-kit


    【解决方案1】:

    终于解决了。 我把 enumerateChildNodesWithName 放到一个子线程里,把 [bubbleNode crashed] 放到主线程里。 所以这个枚举不会影响节点的移动。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多