如何在精灵套件节点的纹理上关闭抗锯齿

时间:2023-01-23 07:54:06

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.

我正在尝试将测试游戏放在Sprite Kit中。我有一些代码使用一对尺寸为200 * 572的PNG图像创建一块地面。

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: 如何在精灵套件节点的纹理上关闭抗锯齿

输入我的问题。这是我在Xcode文件查看器中的精灵的近距离:

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?

这就是游戏运行时的样子:游戏中的精灵似乎是消除锯齿的,结果看起来很模糊。如何防止这种情况并使游戏看起来像原始图像一样清晰?

1 个解决方案

#1


6  

You will need to change the filteringMode on your SKTexture objects to SKTextureFilteringMode.Nearest.

您需要将SKTexture对象上的filteringMode更改为SKTextureFilteringMode.Nearest。

Then as long as your node is positioned on pixel boundaries, it should be drawn as expected.

然后,只要您的节点位于像素边界上,就应该按预期绘制它。

#1


6  

You will need to change the filteringMode on your SKTexture objects to SKTextureFilteringMode.Nearest.

您需要将SKTexture对象上的filteringMode更改为SKTextureFilteringMode.Nearest。

Then as long as your node is positioned on pixel boundaries, it should be drawn as expected.

然后,只要您的节点位于像素边界上,就应该按预期绘制它。