Converting tiles to sprite nodes in XCode Swift

我们两清 提交于 2020-01-17 03:37:22

问题


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:


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.

Create objects in your map and name them.

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);
    }


来源:https://stackoverflow.com/questions/30379805/converting-tiles-to-sprite-nodes-in-xcode-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!