#import "JsTileMap.h"#import "LFCGzipUtility.h"
接下来只需进入SKScene文件并创建一个tileMap变量,如下所示:
var tileMap = JsTileMap(named: "tileMap.tmx")
我发现定位有点棘手,所以生病了.
self.anchorPoint = CGPoint(x: 0,y: 0)self.position = CGPoint(x: 0,y: 0) //Change the scenes anchor point to the bottom left and position it correctlylet rect = tileMap.calculateAccumulatedFrame() //This is not necessarily needed but returns the CGRect actually used by the tileMap,not just the space it Could take up. You may want to use it latertileMap.position = CGPoint(x: 0,y: 0) //position in the bottom leftaddChild(tileMap) //Add to the scene
编辑
下面是我用来创建SKSpriteNodes楼层的代码:
func addFloor() { for var a = 0; a < Int(tileMap.mapSize.wIDth); a++ { //Go through every point across the tile map for var b = 0; b < Int(tileMap.mapSize.height); b++ { //Go through every point up the tile map let layerInfo:TMXLayerInfo = tileMap.layers.firstObject as TMXLayerInfo //Get the first layer (you may want to pick another layer if you don't want to use the first one on the tile map) let point = CGPoint(x: a,y: b) //Create a point with a and b let gID = layerInfo.layer.tileGIDAt(layerInfo.layer.pointForCoord(point)) //The gID is the ID of the tile. They start at 1 up the the amount of tiles in your tile set. if gID == 2 || gID == 9 || gID == 8{ //My gIDs for the floor were 2,9 and 8 so I checked for those values let node = layerInfo.layer.tileAtCoord(point) //I fetched a node at that point created by JsTileMap node.physicsBody = SKPhysicsBody(rectangleOfSize: node.frame.size) //I added a physics body node.physicsBody?.dynamic = false //You Now have a physics body on your floor tiles! :) } } } }总结
以上是内存溢出为你收集整理的ios – 如何在swift中使用JSTileMap全部内容,希望文章能够帮你解决ios – 如何在swift中使用JSTileMap所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)