Reputation: 43
I have a question which I am breaking my brains over for the last hours. I am creating a tiled map, and as textures for the tiles I have some spritesheets.
I can demonstrate my issue with the following spritesheet:
Now I use the SKtexture(rect: , in:) method to get the tile textures out of the spritesheet. My problem is that when I use this method, somehow there seems to exist a very small offset, so that when I for example want to render a map filled with the lowest left sprite (just snow) I can see a very small part of the tile above it.
I can demonstrate this with the following screenshot:
As you can see, there are some blue lines between the tile rows. This is the code I used for the example, it is an extract of the tilemap parser I use but it shows the same behaviour.
let source = SKTexture(imageNamed: "snowiceCor")
let superNode = SKNode()
let sourceWidth = source.size().width
let sourceHeight = source.size().height
let tileSize: CGFloat = 32.0
let tileX: CGFloat = 0
let tileY: CGFloat = 8
for i in 0...8 {
for j in 0...8 {
let rX = (tileSize * tileX) / sourceWidth
let rY = CGFloat(1) - ((tileSize * tileY) / sourceHeight)
let rW = tileSize / sourceWidth
let rH = tileSize / sourceHeight
let rect = CGRect(x: rX, y: rY, width: rW, height: rH)
let texture = SKTexture(rect: rect, in: source)
let node = SKSpriteNode(texture: texture, color: .clear, size: CGSize(width: tileSize, height: tileSize))
superNode.addChild(node)
node.zPosition = 99
node.position.x = CGFloat(i*32)
node.position.y = CGFloat(j*32)
}
}
addChild(superNode)
superNode.setScale(2)
I hope someone can help me with this.
Upvotes: 1
Views: 669
Reputation: 1241
The blue line is probably anti-aliasing kicking in. You can turn this off by setting 'filteringMode = .nearest' on the textures. Alternatively (if you want the anti-aliasing), you could pad the tiles with transparent pixels).
Upvotes: 1