Sprite Atlas 和@2x 图像 [英] Sprite Atlas and @2x images

查看:26
本文介绍了Sprite Atlas 和@2x 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用纹理图集 (iPhone5) 时,我是否必须包含正常和 normal@2x 尺寸的精灵图像(即使我只针对视网膜设备).我以为我可以只添加@2x 版本就可以逃脱,但遗憾的是,当我运行应用程序时,精灵出现的尺寸比它们应有的大很多(近 4 倍),当我添加正常时,我只会显示正确大小的精灵(@1x) 图像到图集.

When using texture atlas (iPhone5) do I have to include sprite images at both normal and normal@2x sizes (even though I am only targeting retina devices). I thought I could getaway with only adding the @2x versions but sadly when I run the application the sprites come out a lot bigger than they should be (nearly 4x), I only get the right size sprites displayed when I add the normal (@1x) images to the atlas as well.

在 Xcode 中启动一个新的项目文件,如果你想让一个图像填满整个设备显示屏(iPhone5/5S 在最大分辨率下)你需要使用@2x 扩展名(在这种情况下没有 "background_003.png"在 Xcode 项目中,所以只需 @2x 版本就可以了)

Starting a new project file in Xcode, if you want an image to fill the whole device display (iPhone5/5S at the maximum resolution) you need to use the @2x extension (in this case there is no "background_003.png" in the Xcode project so just the @2x version is fine)

    // SETUP BACKGROUND FRAME IS {320, 568} POINTS
    // IMAGE "background_003@2x.png" = 640 x 1136 Pixels
    SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"background_003"];
    [background setAnchorPoint:CGPointZero];
    [background setPosition:CGPointZero];
    [self addChild:background];

如果您在没有@2x 的情况下添加正确大小的图像 (640 x 1136),Xcode 会获取图像并将其错误地按设备 2.0 磅值缩放,导致图像是显示器的两倍.

If you add the correct sized image (640 x 1136) without the @2x Xcode takes the image and scales it incorrectly by the devices 2.0 point size, resulting in an image that is twice as big as the display.

    // SETUP BACKGROUND FRAME IS {320, 568} POINTS
    // IMAGE "background_001.png" = 640 x 1136 Pixels
    SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"background_001"];
    [background setAnchorPoint:CGPointZero];
    [background setPosition:CGPointZero];
    [self addChild:background];

今天早上经过一些测试后,我现在意识到我的问题是在没有@2x 后缀的图集中添加精灵帧然后重命名它们以包含缺少的@2x.似乎当使用 folder.atlas Xcode 在某处创建一个引用文件的 plist 时,我找不到它,而且它似乎只有在您第一次将图集添加到项目时才会更新.删除并重新添加图集后,Xcode 开始以正确的比例正确显示 @2x 图像.

After a little bit of testing this morning I have now realised that my problem was the result of adding sprite frames in an atlas without the @2x postfix and then renaming them to include the missing @2x. It would seem that when using folder.atlas Xcode creates a plist somewhere that references the files, I can't find this and it only seems to get updated when you first add your atlas to your project. After deleting and re-adding the atlas Xcode started correctly displaying the @2x images at the right scale.

因此,这个故事的寓意是:如果您更改了地图集或其内容,请制作一个副本,将其从您的 Xcode 项目中删除并重新添加.以视网膜分辨率创建所有艺术品并将@2x 后缀添加到所有文件中,您只需要不需要视网膜文件(如果您的目标是非视网膜设备,则不需要@2x)最后在代码中引用艺术资产时不要使用@2x 后缀,因此即使您的怪物精灵艺术被称为Monster_0001@2x.png",您也应该在代码中将其称为Monster_0001",Xcode 会在幕后为您计算出@2x 位,如果您使用PNG(你应该是)它甚至会为你添加.png".

The moral of this story is therefore: if you change an atlas or its contents, make a copy, delete it from your Xcode project and re-add it again. Create all your artwork at retina resolution and add the @2x postfix to all your files, you only need none retina files (without the @2x if your targeting a none retina device) Finally when referring to art assets in code don't use the @2x postfix, so even though your monster sprite art is called "Monster_0001@2x.png" you should be referring to it in code as "Monster_0001" Xcode will work out the @2x bit for you behind the scenes, also if your using PNGs (which you should be) it will even add the ".png" for you too.

// THE ART ASSET ON DISK IS CALLED: "Monster_0001@2x.png"
SKSpriteNode *spriteMonster = [SKSpriteNode spriteNodeWithImageNamed:@"Monster_0001"];

推荐答案

如果您只支持 Retina 设备,只需添加不带 @2x 的文件即可.

If you only support Retina devices just add files without the @2x and you'll be fine.

这篇关于Sprite Atlas 和@2x 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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