È possibile utilizzare JSTileMap
in modo rapido e, in caso affermativo, come si usa. Se non riesco a usarlo in fretta, o se è troppo bacato, allora c'è qualcos'altro che posso usare per le mappe .tmx. nota, sto usando il kit spriteCome utilizzare JSTileMap in swift
risposta
Sì, è possibile, ho appena iniziato a usarlo ieri e non ho ancora riscontrato alcun problema! Inizia importando i file JSTileMap e il framework libz.dylib. Quindi aggiungere un'intestazione colmare con le seguenti importazioni:
#import "JSTileMap.h"
#import "LFCGzipUtility.h"
Successivo basta andare in voi lima SKScene e creare una variabile tilemap come illustrato di seguito:
var tileMap = JSTileMap(named: "tileMap.tmx")
Ho trovato il posizionamento un po 'difficile così male add anche quello
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
EDIT
sotto è il codice che ho usato per creare un piano di 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! :)
}
}
}
}
Ho ottenuto il codice per trasformare i blocchi di mappe delle tessere in SKSpriteNodes anche se non l'hai richiesto, quindi non mi sono preoccupato di postare. Basta chiedere se ti piacerebbe. –
Grazie mille !!! Dovrebbe essere bello se tu potessi aggiungerlo, ma questo da solo è oltre utile! –
@MarkCalhoun non è un problema, ho aggiunto il codice extra per te, speriamo che sia documentato abbastanza bene. –
- 1. Come utilizzare UILocalNotification in Swift
- 2. Come utilizzare dequeueReusableCellWithIdentifier in Swift?
- 3. Come utilizzare addAttribute in Swift
- 4. Come utilizzare UILongPressGestureRecognizer con UICollectionViewCell in Swift?
- 5. Come utilizzare l'associazione opzionale in Swift 2
- 6. Come utilizzare dispatch_queue_create in Swift 2.0?
- 7. Come utilizzare un UISplitViewController in Swift
- 8. come utilizzare blocco/chiusura in swift
- 9. Come utilizzare pedice e apice in Swift
- 10. Come utilizzare "enumerateChildNodesWithName" con Swift in SpriteKit?
- 11. Come utilizzare struct Swift in Objective C
- 12. Come utilizzare AnyClass in Swift Classe generica
- 13. Come utilizzare Realm Swift Init
- 14. Come utilizzare TouchID utilizzando Swift?
- 15. Come utilizzare asl.h nei file swift-ios
- 16. Come utilizzare numeri negativi in un intervallo in Swift?
- 17. Come utilizzare NSURL in Swift in Xcode 6.1?
- 18. come utilizzare uiswitch per selezionare la categoria in swift?
- 19. Come utilizzare correttamente CFNotificationCenterAddObserver in Swift per iOS
- 20. Come posso utilizzare Swift 2.3 in XCode 8 Playgrounds?
- 21. Come utilizzare i Cocoapod Objective-C in un progetto Swift?
- 22. Come utilizzare completamentoHandler Chiusura con ritorno in Swift?
- 23. Come utilizzare una IBAction per più pulsanti in Swift?
- 24. Come utilizzare openURL per effettuare una telefonata in Swift?
- 25. Quando e come utilizzare l'attributo @noreturn in Swift?
- 26. Come utilizzare enumerazioni come parametri a Swift Protocolli funzioni opzionali
- 27. NSTimer - come ritardare in Swift
- 28. Swift: String contiene String (senza utilizzare NSString)?
- 29. Swift - Utilizzare init-metodo diverso per dequeueReusableCellWithIdentifier
- 30. Come utilizzare _printHierarchy nella console LLDB con Swift?
[TilemapKit] (http://tilemapkit.com) è pienamente compatibile con Swift. Basta dire;) – LearnCocos2D