- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在浏览 Apple 的 SpriteKit 文档时发现了一个非常有用的功能,我可以在编写 UI 时使用它。问题是我无法让它工作。
请查看此页面并向下滚动到“调整 Sprite 大小”- Apple Docs
我从字面上复制了图像尺寸并使用了相同的代码以防我做错了什么。但我总是以拉伸(stretch)的图像结束,而不是保持相同比例的正确“端盖”。
我指的是这段代码:
SKSpriteNode *button = [SKSpriteNode spriteWithImageNamed:@"stretchable_button.png"];
button.centerRect = CGRectMake(12.0/28.0,12.0/28.0,4.0/28.0,4.0/28.0);
我做错了什么?有没有我错过的步骤?
编辑:
这是我一直在使用的代码。我将它从我的按钮类中剥离并尝试将它与 SKSPriteNode 一起使用,但问题仍然存在。我还更改了图像以确保不是那样。我使用的图像是正常尺寸的 32x32。
SKSpriteNode *button = [SKSpriteNode spriteNodeWithImageNamed:@"Button.png"];
[self addChild:button];
button.position = ccp(200, 200);
button.size = CGSizeMake(128, 64);
button.centerRect = CGRectMake(9/32, 9/32, 14/32, 14/32);
最佳答案
如果您调整 sprites 的 .scale 属性,.centerRect 属性将按照记录的方式工作。
尝试:
SKTexture *texture = [SKTexture textureWithImageNamed:@"Button.png"];
SKSpriteNode *button = [[SKSpriteNode alloc] initWithTexture:texture];
button.centerRect = CGRectMake(9/32, 9/32, 14/32, 14/32);
[self addChild:button];
button.xScale = 128.0/texture.size.width;
button.yScale = 64.0/texture.size.height;
关于iOS Sprite Kit - SKSpriteNode 的 .centerRect 属性不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19715128/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!