I have a SpriteKit game in which there's a shape created via SKShapeNode(splinePoints:count:)
.
The shape has a fillTexture
, loaded from a texture atlas via textureNamed(_:)
.
In my texture atlas there are 5 images -- 1 of which is used for the shape.
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. Also, the texture works correctly if it's the only image in the atlas. It's when I add additional images that the problem occurs.
Here's the code that results in the correct texture:
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)
Expected results:
The shape, which has a purple gradient image, should look like this (please ignore the dotted white line):
Actual results:
Instead, the shape looks like this, with strange blank areas and little artifacts from the other images located in the atlas:
Here's the version of code that uses the atlas:
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)
Why is this problem happening, and how do I resolve it?
Thank you!
question from:
https://stackoverflow.com/questions/66053157/spritekit-texture-atlas-leads-to-image-artifacts-and-blank-areas 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…