'SKLabelNode blurry when zoomed in with SKCameraNode
I'm having a problem that I just can't solve. I've been looking for hours now to fix this, I can't find anything.
I have SKScene that got a SKShapeNode and SKLabelNode. I'm also using a SKCameraNode that's zooming into the scene (using a scale action). When I do this, it looks like this:
The circle is sharp (though it's not pretty) but the main problem is the label that clearly blurry.
Is there a way to keep the label sharp when zooming in? If not, what a better way to zoom into a scene without losing quality?
Thanks guys!
Solution 1:[1]
SKLabelNode unfortunately gets blurry when the camera zooms in.
If the SKLabelNode were a child on the SKCameraNode the problem would not occur, but this is only helpful on a scoreboard or HUD that the camera movement should not impact.
A dirty solution for a higher-quality SKLabelNode is to render it with a large font size, convert it to an SKSpriteNode and then scale it down again:
let scaleFactor = 5.0
let label = SKLabelNode(text: "Test")
label.fontSize = 12.0 * scaleFactor
let spriteText = SKSpriteNode(texture: view.texture(from: label))
spriteText.xScale = 1 / scaleFactor
spriteText.yScale = 1 / scaleFactor
addChild(spriteText)
You can try various values for the scaleFactor and see if the result is to your liking.
(Note that if you don't have access to your view you can use SKView().texture(from: label) in line 5).
Solution 2:[2]
The SKCameraNode has its own scale function, so you wouldn't need to use a scale action.
guard let camera = self.childNode(withName: "gameCamera") as? SKCameraNode else {
fatalError("Camera node not loaded")
}
camera.setScale(1.75)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | hotdogsoup.nl |
| Solution 2 | Mark Brownsword |

