ios - SKLabelNode 在 SKSpriteNode 后面绘制

标签 ios objective-c sprite-kit

为什么我的 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/

相关文章:

ios - react-native 错误 RCTJSONStringify() 遇到以下错误 : Invalid type in JSON write (NSURL)

ios - 使用 AFNetworking 解析 JSON 文件

ios - UITableView部分中的多种单元格类型

swift - 物理体 : Could not create physics body

ios - Spritekit 物理和相机平滑

ios - 'FIRInstanceID' 没有可见的@interface 声明选择器 'setAPNSToken:type:'

ios - 从设备中删除本地 icloud 文件?

ios - 未调用 Objective-C UIKit UIAlertViewDelegate

swift - 使 SKLabelNode 忽略触摸

ios - 使用 MKPolyline 在 MKMapView 中绘制多组线