swift - 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)
为什么会出现这个问题,我该如何解决?
谢谢!
解决方案
It looks like I've solved the problem, though I'm not sure why my solution works.
Instead of having a top-level .atlas
folder, I've put a .spriteatlas
folder inside Assets.xcassets
.
For whatever reason, this results in the correct textures being shown without any nasty artifacts or transparent areas.
推荐阅读
- string - 通过 python 字符串导入和导出 netlogo 世界
- android - 单元测试 viewModel 和 livedata Mockito android
- autohotkey - 使用半透明的 AHK 创建一个窗口
- jasper-reports - 如何在 jasper studio 表中的表中添加额外的行?
- simulation - 使用 NetEdit 反转边缘流向
- java - tomcat中的SPNEGO总是提示密码
- selenium - 所以我们制作了一个使用 selenium 的不和谐机器人,我们决定将它托管在 heroku 上
- jasmine - 在用于 ios 自动化的 appium 和 wdio 中使用时遇到 isClickable() 的问题
- casting - 覆盆子零 w - 相机 udp 流错误
- xml - xs:element 和 s:element 有什么区别