【发布时间】:2021-02-04 20:12:21
【问题描述】:
我有一个 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)
为什么会出现这个问题,我该如何解决?
谢谢!
【问题讨论】:
-
你能包括它成功的方式吗?
If I use the regular .xcassets folder instead of an atlas, the shape is textured correctly. So it's definitely an issue with the atlas. -
@impression7vx 我编辑了问题以包含使用 .xcassets 正常工作的代码。谢谢。
-
以“正确”的方式进行操作有什么问题?
-
@impression7vx 据我了解,使用纹理图集是一种性能增强,可以减少渲染场景所需的绘制调用次数。所以我想用它。
标签: swift sprite-kit