在 XCode Swift 中将图块转换为精灵节点 [英] Converting tiles to sprite nodes in XCode Swift

查看:66
本文介绍了在 XCode Swift 中将图块转换为精灵节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个小游戏,我使用 Tiled 程序绘制了地图.假设我使用了一组三张图片;我如何将它们转换"为 SKSpriteNodes?假设有一张代表角色的瓦片和三张代表地面的瓦片.我希望这四个是精灵节点.

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.

提前致谢

推荐答案

我无法为您提供 Swift 版本的帮助,但请查看以下图片以更好地理解我在说什么.

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.

在平铺中创建对象层.

在地图中创建对象并为其命名.

我假设您正在使用 Tiled 应用程序来创建您的地图.您可以在 Tiled 应用程序中为您的地图创建一个对象图层.完成后,只需在地图中创建各种对象即可.例如,创建多个名为敌人"的对象.该对象层将由 JSTileMap 读取,您可以像这样在代码中访问:

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

这篇关于在 XCode Swift 中将图块转换为精灵节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆