Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

ios - Spritekit - not loading @3x images from SKTextureAtlas

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.

Here are sample images

2x image

my 3x image

My atlas setup:

enter image description here

My launch image setup:

enter image description here

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)

}

These are my results:

iPhone 5 simulator:

enter image description here

iPhone 6 plus simulator:

enter image description here

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.

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 ...

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

enter image description here

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

enter image description here

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)

Hint:

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...