0
votes

I am developing a mini-game and I've drawn the map by using the program Tiled. Let's assume that I've used a tile set of three pictures; how do I 'convert' them to SKSpriteNodes? Let's say that there is one tile representing the character and three tiles representing ground. I want these four to be sprite nodes.

Thanks in advance

1
Are you asking how to place these images on the screen?sangony
No they appear on the screen when I load the tilemap. But what I am asking for is that for instance I have a character on the screen (from my tilemap.tmx file) which I want to do some stuff with such as SKActions. How can I some sort of 'convert' all unit types in to SKSpriteNodes? Let's say that I have 1 player character and 3 monsters in my tilemap. I want them as SKSpriteNodes so I can interact with them with actions.toom4ny
To mention, I've used different layers. So whenever I put the character I have named it as 'Bob' in my tilemap (using the program Tiled). Maybe this will help me but I have no clue how.toom4ny

1 Answers

1
votes

I can't help you with the Swift version but look at the below pics to get a better understanding of what I am talking about.

Create an Object Layer in Tiled.

enter image description here

Create objects in your map and name them.

enter image description here

I assume you are using the Tiled app to create your maps. You can create an object layer for your map in the Tiled app. Once done, simply create various objects in your map. For example, create several objects called "enemy". This object layer will be read by JSTileMap and will be accessible to you in your code like this:

TMXObjectGroup *group = [tiledMap groupNamed:@"objectLayer"];
// make sure the you use the same groupNamed as is in your map!

NSArray *floorObjects = [group objectsNamed:@"enemy"];
    for (NSDictionary *floorObj in floorObjects)
    {
        CGFloat x = [floorObj[@"x"] floatValue];
        CGFloat y = [floorObj[@"y"] floatValue];
        CGFloat w = [floorObj[@"width"] floatValue];
        CGFloat h = [floorObj[@"height"] floatValue];

        // create your SKSpriteNode here
        // use the x, y as the node's position in the map
        // myNode.position = CGPointMake(x, y);
    }