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

查看:88
本文介绍了如何在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.

如果您确实需要显示经常变化的大范围数字,但仍然需要它们受到物理影响,那么您可能会问自己,我是否应该创建一个图像,并且我可能会尽一切可能分配给我的spritenode?答案是不.您可以将标签尺寸设置为超出所需的尺寸,然后将其缩小.要处理物理,您可以将此标签添加为某些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天全站免登陆