SKTileMapNode未加载到正确的大小

时间:2018-05-21 03:01:16

标签: swift sprite-kit sktilemapnode

对于我目前正在处理的项目,我将两个SKTileMapNodes堆叠在一起。它们的行数,列数以及图块大小不同。但是,它应该等同于它们的总宽度和高度相同。

问题是,尽管行,列和图块大小正确,但其中一个图块图的尺寸不正确。

第一个SKTilMapNode(正确大小)

class Map:SKTileMapNode {

  func initMap() {

    name = "Map"

    tileSet = SKTileSet(named: "tileSet")!
    numberOfColumns = 32
    numberOfRows = 32
    tileSize = CGSize(width: 32, height: 32)
    position = CGPoint(x: 0, y: 0)
    anchorPoint = CGPoint(x: 0.5, y: 0.5)

    self.fill(with: self.tileSet.tileGroups[4])

  }

}

第二个SKTileMapNode(不正确的大小)

class PaintLayer:SKTileMapNode {

    func initPaintLayer() {

        name = "PaintLayer"

        tileSet = SKTileSet(named: "tileSet")!
        numberOfColumns = 32*4
        numberOfRows = 32*4
        tileSize = CGSize(width: 32/4, height: 32/4)
        position = CGPoint(x: 0, y: 0)
        anchorPoint = CGPoint(x: 0.5, y: 0.5)

        self.fill(with: self.tileSet.tileGroups[1])

    }

}

在游戏场景中初始化

class GameScene: SKScene {

  var map:Map = Map()
  var paintLayer:PaintLayer = PaintLayer()
  var player:Player = Player(imageNamed: "player")

  override func didMove(to view: SKView) {

      let camera:SKCameraNode = SKCameraNode()
      self.camera = camera
      self.addChild(camera)

      map.initMap()
      self.addChild(map)

      paintLayer.initPaintLayer()
      self.addChild(paintLayer)

      player.initPlayer()
      self.addChild(player)

  }

}

结果

Result

0 个答案:

没有答案