ios – 如何在swift中使用JSTileMap

你可以在 swift中使用JSTileMap吗?如果是的话,你如何使用它?如果我不能在swift中使用它,或者它太麻烦了,那么还有什么我可以用于.tmx地图.请注意,我正在使用精灵工具包

解决方法

是的,你可以,我昨天刚开始使用它,还没有发现问题!首先导入JSTileMap文件和libz.dylib框架.然后使用以下导入添加桥接标头:
#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 correctly


let 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 later
tileMap.position = CGPoint(x: 0,y: 0) //Position in the bottom left
addChild(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! :)
                }
            }
        }
    }

相关文章

背景 前端时间产品经理决定使用百度统计,使得 工程B 中原统计sdk-友盟统计,需要被去除。之前尝试去除...
结论: alloc负责分配内存和创建对象对应的isa指针; init只是返回alloc生成的对象。 所以alloc后,多次...
更新 如果UI愿意把启动图切割成n份,按一定约束在launchscreen.storyboard中进行排版,启动图效果会更好...
最近在看一本书《Effective OC 2.0》,今天看到有个tip是OC适中循环各自优劣性,作者最终推荐此块循环。...
// // ViewController.m // paintCodeTestOC //gif // Created by LongMa on 2019/7/25. // #import &a...
背景介绍 一般情况下,出于省电、权限、合理性等因素考虑,给人的感觉是很多奇怪的需求安卓可以实现,但...