雪碧地图集和@ 2x图像 [英] Sprite Atlas and @2x images

查看:88
本文介绍了雪碧地图集和@ 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扩展名(在这种情况下, Xcode项目中的"background_003.png",因此只需使用@ 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];

如果添加正确大小的图像(640 x 1136),而没有@ 2x 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),它甚至还会为您添加".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.

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

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