Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off anti aliasing on a sprite kit node's texture

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: enter image description here

And here's what it looks like when the game is running:enter image description here 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?

like image 375
PopKernel Avatar asked Feb 09 '23 02:02

PopKernel


1 Answers

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.

like image 181
Craig Siemens Avatar answered Feb 10 '23 22:02

Craig Siemens