0

I tried to position the Tile Map so that the bottom left of it is attached to the bottom left of the screen. Below is the code i tried to use:

func setUpSceneWithMap(map: SKTileMapNode) {
        let tileMap = map

        tileMap.setScale(1)
        tileMap.position = CGPoint(x: 0 - self.frame.size.width/2, y: 0 - self.frame.size.height/2)
                    ...
        tileMap.addChild(tileNode)

    }

Noted that I added the tile map using the GameScene.sks and not programatically. I was hoping that the position of the map should work as defined. However, when i tried to run it, the map did move, but the image that i used for my tile stayed at the same location and refused to update. Instead, it created the weird texture as follow. Please see attached image to see what happen. I am stuck at this for days and appreciate any help...

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Khoi Le
  • 3
  • 4

1 Answers1

1

Add this

self.tileMap?.anchorPoint = .zero

This is the complete example:

https://github.com/Maetschl/SpriteKitExamples/blob/master/CenterTileMap/CenterTileMap/GameScene.swift

And the image:

enter image description here

Maetschl
  • 1,330
  • 14
  • 23
  • I tried it before, both by code as you shown and by changing it from the .sks file, it didn't work. Even weirder, if you look at the attached image on my post, the tiles did change the position, but not its image. So basically when i move the character, the wall is where the empty box place and not where the image is. – Khoi Le May 25 '20 at 17:04
  • Then improve your question. This answer is simple for a simple question, you have other problems whit characters and walls? – Maetschl May 25 '20 at 18:51
  • Ok Maetschl, i appreciate your help. I'm new to the whole coding world and trying to learn by myself. I attached an image in my question at the beginning, did you try to see it yet? If you click to the link, you will see that the image is not moving along with the tiles, which is frustrating for me. – Khoi Le May 25 '20 at 19:29