gpt4 book ai didi

ios - SKLabelNode 在 SKSpriteNode 后面绘制

转载 作者:行者123 更新时间:2023-11-28 19:03:39 25 4
gpt4 key购买 nike

为什么我的 SKLabelNode 总是在我的 SKSpriteNode 后面绘制,即使我在 sprite 之后添加它?

    _startButton = [SKSpriteNode spriteNodeWithImageNamed:@"start@2x.png"];
_startButton.position = CGPointMake(self.frame.size.width/2,self.frame.size.height/2);
_startButton.name = @"start";
_startButton.zPosition = 1.0;
[self addChild:_startButton];

SKLabelNode *start = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
start.text = @"Start";
start.fontSize = 40;
start.fontColor = [SKColor whiteColor];
start.position = CGPointMake(self.size.width/2, self.size.height/2);
[self addChild:start];

最佳答案

我很确定默认的 zPosition 为 0,这意味着您的 Sprite (zPosition 为 1)将出现在标签前面。尝试将 SKLabelNode zPosition 设置为 2。较大的正数会将项目放在较小数字的项目之上。

The default value is 0.0. The positive z axis is projected toward the viewer so that nodes with larger z values are closer to the viewer. When a node tree is rendered, the height of each node (in absolute coordinates) is calculated and then all nodes in the tree are rendered from smallest z value to largest z value. If multiple nodes share the same z position, those nodes are sorted so that parent nodes are drawn before their children, and siblings are rendered in the order that they appear in their parent’s children array. Hit-testing is processed in the opposite order.

关于ios - SKLabelNode 在 SKSpriteNode 后面绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22519546/

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