简体   繁体   English

SpriteBuilder CCButton拉伸图像?

[英]SpriteBuilder CCButton stretched images?

In spritebuilder, the tool to create UI along with cocos2d, how come whenever I try to add a background image to a CCButton, it appears stretched or altered in some way? 在spritebuilder中,它是与cocos2d一起创建UI的工具,当我尝试将背景图像添加到CCButton时,它为什么会以某种方式出现拉伸或改变,怎么会这样呢?

It is hard to explain but after fiddling with every CCButton option for 20 minutes this is the closest I could get it. 很难解释,但是在摆弄了每个CCButton选项20分钟之后,这是我能得到的最接近的结果。 The first image is the original image and the second in the image in SpriteBuilder. 第一个图像是原始图像,第二个图像是SpriteBuilder中的图像。

在此处输入图片说明

在此处输入图片说明

As you can see in the second image, the edges seem jagged a bit and are curving in the wrong direction. 如您在第二张图像中看到的,边缘看起来有些锯齿,并且弯曲方向错误。 Can anyone explain to me why this is happening and how I can fix this? 谁能向我解释为什么会发生这种情况以及我该如何解决?

Thanks! 谢谢!

I got this settings to work correctly by clicking the "Reset to default size" button. 通过单击“重置为默认大小”按钮,我使此设置正常工作。 It automatically set the Preferred Size to half the width and height of my original image (since my 'default scaling' is set to '2x' in File->Project Settings). 它将自动将“首选大小”设置为原始图像的宽度和高度的一半(因为在“文件”->“项目设置”中将“默认缩放比例”设置为“ 2x”)。

To keep the button size intact while adding text then set the 'max size' property to the same as 'preferred size'. 要在添加文本时保持按钮大小不变,请将“最大大小”属性设置为与“首选大小”相同。

CCButton uses a CCSprite9Slice and you need to set the preferred size of the button to solve your problem. CCButton使用CCSprite9Slice ,您需要设置按钮的preferred size来解决您的问题。 If the preferred size matches the image size then the image will not be stretched: 如果首选大小与图像大小匹配,则将不会拉伸图像:

在此处输入图片说明

You also need to take the scaling factor into account. 您还需要考虑比例因子。 If the you provide the image as a 4x asset, you need to set preferred size to 1/4 of the image size. 如果您将图像作为4倍资源提供,则需要将首选尺寸设置为图像尺寸的1/4。

如果创建了图像,请尝试对其进行编辑,这样就不必缩放图像。

I just ended up subclassing CCSprite and just adding my own touch controls to that. 我刚刚结束了CCSprite的子类化,并向其中添加了自己的触摸控件。 Now it looks great! 现在看起来很棒!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM