I'm currently trying to put a test game together in Sprite Kit. I have some code that creates a patch of ground using a pair of PNG images with dimensions 200 * 572.
let textures = [SKTexture(imageNamed: "GrassAni1"), SKTexture(imageNamed: "GrassAni2")]
for (var i = 0; i < 10; i += 1) {
let chunk = SKSpriteNode(texture: textures[0])
chunk.position = CGPointMake(CGFloat(200 * i), 0)
let animate = SKAction.animateWithTextures(textures, timePerFrame: 1)
chunk.runAction(SKAction.repeatActionForever(animate))
//boilerplate physics body code…
self.addChild(hero)
}
Enter my problem. Here is an up-close of my sprite in the Xcode file viewer:
And here's what it looks like when the game is running: The in-game sprite appears to be anti-aliased and as a result looks fuzzy. How do I prevent this and make the game look as sharp as the original images?
You will need to change the filteringMode
on your SKTexture
objects to SKTextureFilteringMode.Nearest
.
Then as long as your node is positioned on pixel boundaries, it should be drawn as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With