0

in TileMap we can use layers and one of them is the Object layer. but how is to use them to gave me his position?

with this code I can see the Position of the object, but it does not have 'a member named position'

let group:TMXObjectGroup = tileMap.groupNamed("Blocks")
        let theObjects: [AnyObject] = group.objectsNamed("Wall")
        for i in theObjects {
            print(i)
        }

The Result of the Code

So i can not save the Position in an Var or Let, how we can?

Lirf
  • 111
  • 12

1 Answers1

0

I'm not entirely sure what you're asking, but if I understood you correctly, this will give you what you want:

extension JSTileMap {
  func getObjectPositionOnLayer(layerName: String, objectName: String) -> CGPoint {
    var position = CGPoint()

    if let objectLayer = groupNamed(layerName) {
      if let object: NSDictionary = objectLayer.objectNamed(objectName) {
        position = CGPoint(
          x: object.valueForKey("x") as! CGFloat,
          y: object.valueForKey("y") as! CGFloat
        )
      }
    }

    return position
  }
}

Example usage:

// Get player start position from the object named "Start", in 
// the object layer "Meta Layer".
let startPoint = map.getObjectPositionOnLayer("Meta Layer", objectName: "Start")
player.position = startPoint
jdlm
  • 6,327
  • 5
  • 29
  • 49
  • Do you know how to do it with height and width of the Object? They are not convertible to CGFloat – Lirf Jul 27 '15 at 11:56