如何解决SpriteKit 纹理图集导致图像伪影和空白区域
我有一个 SpriteKit 游戏,其中有一个通过 SKShapeNode(splinePoints:count:)
创建的形状。
形状有一个 fillTexture
,通过 textureNamed(_:)
从纹理图集加载。
在我的纹理图集中有 5 张图像——其中 1 张用于形状。
如果我使用常规的 .xcassets 文件夹而不是图集,则形状的纹理是正确的。所以这绝对是地图集的问题。此外,如果纹理是地图集中的唯一图像,则该纹理可以正常工作。当我添加额外的图片时,问题就出现了。
这是导致正确纹理的代码:
var splinePoints = mainData.getSplinePointsForGround()
let ground = SKShapeNode(splinePoints: &splinePoints,count: splinePoints.count)
let texture = SKTexture(imageNamed: "groundTexture")
ground.fillTexture = texture
ground.linewidth = 1
ground.fillColor = UIColor(Color.purple)
ground.strokeColor = UIColor(Color.clear)
addChild(ground)
预期结果:
具有紫色渐变图像的形状应如下所示(请忽略白色虚线):
实际结果:
相反,形状看起来像这样,有奇怪的空白区域和地图集中其他图像的小瑕疵:
这是使用图集的代码版本:
let textureAtlas = SKTextureAtlas(named: "assets")
var splinePoints = mainData.getSplinePointsForGround()
let ground = SKShapeNode(splinePoints: &splinePoints,count: splinePoints.count)
let texture = textureAtlas.textureNamed("groundTexture2.png")
ground.fillTexture = texture
ground.linewidth = 1
ground.fillColor = UIColor(Color.purple)
ground.strokeColor = UIColor(Color.clear)
addChild(ground)
为什么会出现这个问题,我该如何解决?
谢谢!
解决方法
看起来我已经解决了这个问题,但我不确定为什么我的解决方案有效。
我没有放置顶级 .atlas
文件夹,而是将一个 .spriteatlas
文件夹inside Assets.xcassets
。
无论出于何种原因,这都会导致显示正确的纹理,而没有任何令人讨厌的伪影或透明区域。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。