Comment utiliser JSTileMap dans swift

Pouvez-vous utiliser JSTileMap dans swift, et si oui, comment l'utilisez-vous. Si je ne peux pas l'utiliser dans swift, ou si c'est trop bogué, alors y at-il autre chose que je peux utiliser pour les maps .tmx. note, j'utilise le kit sprite

Oui, vous pouvez, je viens de commencer à l'utiliser hier et je n'ai pas encore trouvé de problème! Commencez par importer les files JSTileMap et le cadre libz.dylib. Ajoutez ensuite un en-tête de pontage avec les imports suivantes:

 #import "JSTileMap.h" #import "LFCGzipUtility.h" 

Ensuite, allez simplement dans votre file SKScene et créez une variable tileMap comme indiqué ci-dessous:

 var tileMap = JSTileMap(named: "tileMap.tmx") 

J'ai trouvé le positionnement un peu difficile si mal append cela aussi.

 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 

MODIFIER

ci-dessous est le code que j'ai utilisé pour créer un étage de 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! :) } } } }