Spritekit - 不从SKTextureAtlas加载@ 3x图像 [英] Spritekit - not loading @3x images from SKTextureAtlas

查看:233
本文介绍了Spritekit - 不从SKTextureAtlas加载@ 3x图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我的示例项目被删除了(我认为这会更容易测试),我会发布一些代码和图片来说明我的观点。

Since my sample project was deleted (I thought this would be much easier to test), I will post some code and images to illustrate my point.

这里有样本图片

我的地图册设置:

我的启动图像设置:

我将这些精灵添加到场景中的代码

The code where I add these sprites to my scene

override func didMoveToView(view: SKView) {
    let texture = SKTextureAtlas(named: "scenery")
    let test = SKSpriteNode(texture: texture.textureNamed("test"))
    test.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
    self.addChild(test)

}

这些是我的结果:

iPhone 5模拟器:

iPhone 5 simulator:

iPhone 6加模拟器:

iPhone 6 plus simulator:

我尝试更改启动图像以使用资产目录。然后iPhone 6 plus似乎升级了2倍的屏幕。它仍在加载2x图像,但会将其缩放。

I've tried changing the launch image to use the asset catalog. Then the iPhone 6 plus seems to upscale a 2x screen. It's still loading the 2x image, but scales it up.

我需要它来加载我的3x图像并使用我的2x图像进行缩放。

I need it to load my 3x image and be to scale with my 2x image.

Gabuh的回答指出了我正确的方向。适用于新项目。但是,如果我将他的解决方案用于我的真实SpriteKit项目,我的3x图像不会缩小。它们比它们应该大3倍。

Gabuh's answer below pointed me in the right direction. Works on a new project. However, if I use his solution for my real SpriteKit project my 3x images don't get downscaled. They are 3x bigger than they should be.

推荐答案

如果你正在使用一种新方法创建地图集,它似乎现在正在工作。重要的是部署目标应该> = 9.0 ...

It seems to be working now if you are using a new way to create atlas. Important thing is that Deployment target should be >= 9.0 ...

选择资产.xcassets 然后点击+符号创建一个新的精灵地图集:

Select Assets.xcassets and click to + sign to create a new sprite atlas:

选择New Sprite Atlas选项并添加@ 2x和@ 3x资产:

Choose "New Sprite Atlas" option and add @2x and @3x assets :

然后在代码中执行以下操作:

Then in a code do this:

let sprite = SKSpriteNode(texture: SKTextureAtlas(named: "Sprites").textureNamed("test"))
sprite.position = CGPoint(x: frame.midX, y: frame.midY)
addChild(sprite)

提示:

如果您在模拟器上进行测试,请重置模拟器的内容并进行设置在尝试之前清除缓存。

If you are testing on Simulator, reset Simulator's content and settings to clear the cache before you try this.

这篇关于Spritekit - 不从SKTextureAtlas加载@ 3x图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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