我应该如何调整 SpriteKit 中标签节点的大小? [英] How should I resize label nodes in SpriteKit?

查看:12
本文介绍了我应该如何调整 SpriteKit 中标签节点的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的场景中有几个 SKLabelNodes,如下所示:

So I have a couple of SKLabelNodes in my scene like this:

SKLabelNode *label1 = [SKLabelNode labelNodeWithFontNamed:@"Arial"];
label1.text = @"Hello World!";
label1.fontColor = [SKColor redColor];
label1.fontSize = 90;
label1.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame));
[self addChild: label1];

当场景开始时,我希望他们扩大规模.我为此使用了 SKAction,但 scaleBy 导致文本模糊,并且 resizeTo 不起作用.

And when the scene starts up I want them to scale up. I used an SKAction for this, but scaleBy caused the text to be blurry and resizeTo didn't work.

另外我猜这不是字体的方式.有没有更好的方法来做到这一点,或者我应该使用 UILabels?我不想这样做,因为那意味着我不能在上面使用 SpriteKit 物理,或者我可以吗?

Also I'm guessing this is not the way to go with fonts. Is there a way better way of doing this, or should I use UILabels? I didn't want to do that because that would mean I couldn't use SpriteKit physics on it, or could I?

谢谢

推荐答案

这是我对您的问题的意见.

Here is my input on your issue.

  1. 我永远不会扩大规模.遵循一般准则,如果按比例缩小,通常会保持质量.放大会产生像素艺术的感觉.

  1. I would never scale anything UP. Following general guidelines, if you scale down you are generally going to preserve quality. Scaling up creates that pixel art feel.

如果您不使用标签节点来显示经常变化的数字,请使用 SKSpriteNode.使用基本的照片编辑器键入您的标签并将其保存为您将分配给 spritenode 的图像.Spritenodes 是用来处理物理的,所以你应该使用它们来处理你所有的物理.

If you are not using the label node to display numbers that frequently change, use an SKSpriteNode. Use a basic photo editor to type your label and save it as an image that you would assign to a spritenode. Spritenodes are made to handle physics so you should use them to handle all your physics.

如果您确实需要显示范围广泛且经常变化的数字,但您仍需要它们受到物理影响,您可能会问自己,我是否应该创建一个包含每个可能结果的图像,我可以分配给我的精灵节点?答案是不.您可以将标签大小设置为比您需要的大得多并按比例缩小.要处理物理,您可以将此标签添加为某个具有您希望用于标签的物理属性的 SKSpriteNode 的子节点.现在,您有一个 spritenode 可以根据需要与物理交互,但也有一个标签节点来显示您的信息.

If you do need to display numbers of a wide range that change often but you still need them to be affected by physics, you may ask yourself, am I supposed to create an image with each possible outcome that I could assign to my spritenode? The answer is no. You could set you label size to be way bigger than you need and scale it down. To handle physics, you would add this label as a child of some SKSpriteNode that has the physics properties you wish to use for your label. Now, you have a spritenode that interacts with physics as you desire yet also has a label node that displays your information.

这篇关于我应该如何调整 SpriteKit 中标签节点的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆