The perimeter around a circle gets pixelated when scaling down the image.
缩小图像时,圆周围的像素会变得像素化。
The embedded circle image has a radius of 100 pixels. (The circle is white so click around the blank space, and you'll get the image.) Scaling down using SpriteKit causes the border to get very blurry and pixelated. How to scale up/down and preserve sharp borders in SpriteKit? The goal is to use a base image for a circle and create circle images of different sizes with this one base image.
嵌入的圆形图像的半径为100像素。 (圆圈是白色的,所以点击空白区域,你会得到图像。)使用SpriteKit按比例缩小会使边框变得非常模糊和像素化。如何在SpriteKit中放大/缩小并保留清晰的边框?目标是使用圆形基础图像并使用此基础图像创建不同大小的圆形图像。
// Create dot
let dot = SKSpriteNode(imageNamed: "dot50")
// Position dot
dot.position = scenePoint
// Size dot
let scale = radius / MasterDotRadius
println("Dot size and scale: \(radius) and \(scale)")
dot.setScale(scale)
dot.texture!.filteringMode = .Nearest
1 个解决方案
#1
It seems you should use SKTextureFilteringLinear
instead of SKTextureFilteringNearest
:
看来你应该使用SKTextureFilteringLinear而不是SKTextureFilteringNearest:
SKTextureFilteringNearest:
Each pixel is drawn using the nearest point in the texture. This mode is faster, but the results are often pixelated.
使用纹理中的最近点绘制每个像素。此模式更快,但结果通常是像素化的。
SKTextureFilteringLinear:
Each pixel is drawn by using a linear filter of multiple texels in the texture. This mode produces higher quality results but may be slower.
通过使用纹理中的多个纹素的线性滤波器来绘制每个像素。此模式可产生更高质量的结果,但可能更慢。
You can use SKShapeNode which will act better while scale animation, but end result (when dot is scaled to some value) will be almost pixelated as when using SKSpriteNode and image.
您可以使用SKShapeNode,它在缩放动画时效果更好,但最终结果(当点缩放到某个值时)将几乎像使用SKSpriteNode和图像一样像素化。
#1
It seems you should use SKTextureFilteringLinear
instead of SKTextureFilteringNearest
:
看来你应该使用SKTextureFilteringLinear而不是SKTextureFilteringNearest:
SKTextureFilteringNearest:
Each pixel is drawn using the nearest point in the texture. This mode is faster, but the results are often pixelated.
使用纹理中的最近点绘制每个像素。此模式更快,但结果通常是像素化的。
SKTextureFilteringLinear:
Each pixel is drawn by using a linear filter of multiple texels in the texture. This mode produces higher quality results but may be slower.
通过使用纹理中的多个纹素的线性滤波器来绘制每个像素。此模式可产生更高质量的结果,但可能更慢。
You can use SKShapeNode which will act better while scale animation, but end result (when dot is scaled to some value) will be almost pixelated as when using SKSpriteNode and image.
您可以使用SKShapeNode,它在缩放动画时效果更好,但最终结果(当点缩放到某个值时)将几乎像使用SKSpriteNode和图像一样像素化。