SKATiledMap 是使用免费的 Tiled 地图编辑器创建地图的一个简单解决方案,它支持 .tmx 和 .json 格式 <
Spriting Kit Alliance 欣然提供 SKATiledMap,无需任何保证或保证(有关更多信息,请参阅下面的许可证)。如果缺少某个功能或您想添加某个功能,请发送电子邮件至 [email protected]。
SKATiledMap 基于 SKAToolKit→SKATiledMap,后者是用 Objective-C 编写的。要查看其他酷炫工具,请访问我们的 git hub 页面 https://github.com/SpriteKitAlliance
**特别感谢 Kenney 和他的出色艺术作品 http://kenney.nl/assets
将 SKAToolKit 文件夹中的所有文件复制到您的项目中…是的,就这么简单
现在通过以下方式加载您的地图…
let map = SKATiledMap(mapName: "SampleMapKenney") //name of your JSON file
这是一个表示在 Tiled 中创建的地图的精灵节点。目前 SKATiledMap 只支持 JSON 和 TMX 格式。它也仅支持正交地图。如果我们有足够的需求,我们希望未来添加等距支持。
将您用于瓦片的 JSON 文件和任何图像(请参阅分辨率支持)添加到您的项目中。要将您的瓦片地图保存为 JSON,请在 Tiled 中选择“文件”→“另存为”并选择 .json
在使用Tiled制作地图时,请务必使用1x的贴图资源。当您准备将地图整合到您的应用中以获得最佳效果时,请提供1x、@2x和@3x的贴图资源。请注意SpriteKit和纹理大小的限制。确保您的1x资源不要超过675 x 675(3x的时候将是2025),这是在2048像素限制之下的。就像在Tiled中一样,您只需要导入创建地图时使用的图像。为了获得最佳效果,请将这些图像放入资产目录中。不需要plist文件或参考文件夹。
Tiled支持贴图集合。请确保您的设计使用1x图形。您可以提供1x和2x的.atlas(或者有的是.atlasc如果您的.plist)文件夹,其中包含您用于创建贴图地图的相同图像名称。请记住将.atlas和.atlasc文件夹添加到Xcode作为参考文件夹(它们应该是蓝色的)。目前,@3x在atlas文件夹中不受支持(这在iOS8和更低版本中是这样,但我还没有用iOS9测试过)。
TMX尚未进入公开测试阶段,并且仅支持csv贴图层格式。在保存您的tmx地图之前,请转到地图->地图选项->地图->贴图层格式,并将其设置为CSV。
将tmx地图导入您的应用,并确保找到您为地图使用的所有图像,并将这些图像以及任何@2x和@3x版本导入(如果使用常规贴图集合),或者如果您使用的是集合贴图集合,创建atlas文件夹。更多信息请查看分辨率支持。
创建地图只需调用此方法。
let map = SKATiledMap(mapName: "SampleMapKenney") //name of your tmx file
SKATileMap支持以JSON格式导出的Tiled地图。在Tiled中,将地图导出为JSON文件,并将其导入到您的应用中。当在Tiled中时,请转到文件->另存为并选择JSON。确保找到您为地图使用的所有图像,并导入这些图像以及任何@2x和@3x版本(如果使用常规贴图集合),或者如果您使用的是集合贴图集合,创建atlas文件夹。更多信息请查看分辨率支持。
创建地图只需调用此方法。
let map = SKATiledMap(mapName: "SampleMapKenney") //name of your JSON file
/**
Culling "hiding" nodes that do not need to be rendered
greatly improves performace and frame rate.
This method is optimized to be called every update loop
@param x the center x index you wish to cull around
@param y the center y index you wish to cull around
@param width the number of tiles wide you would like to keep
@param height the number of tiles high you would like to keep
*/
func cullAround(x : Int, y : Int, width : Int, height : Int)
/**
Returns a CGPoint that can be used as an x and y index
@param point the point in which to calculate the index
*/
func index(point : CGPoint) -> CGPoint
/**
This method is used to get custom named objects that you may have
made in Tiled for spawning enemies, player start positions, or
any other custom game logic you made a object for.
*/
func objectsOn(layerNumber: Int, name: String) -> [SKAObject]?
/**
Returns all the tiles around a specific index for a specific point.
Very useful if you need to know
about tiles around a specific index.
@param index the CGPoint that will be used as a x and y index
@param layerNumber the layer in which you would like your tiles
*/
func tilesAround(index : CGPoint, layerNumber : Int)-> [SKASprite?]
/**
Convientent method to quickly get a specific tile for a
specific layer on the map
@param layerNumber the layer in which you would like to use
@param x the x index to use
@param y the y index to use
*/
func spriteFor(layerNumber : Int, x : Int, y : Int) -> SKASprite
SKATiledMap现在具有裁剪功能。当需要更好的性能时,特别是在大地图中,这是很有用的。该方法优化以在更新循环中调用,并会将每个精灵隐藏在指定范围之外。
//for best resutls set a little wider/higher than your viewing area
let playerIndex = map.index(player.position)
map.cullAround(Int(playerIndex.x), y: Int(playerIndex.y), width: 5, height: 5)
所有层都可用。可以进行有趣的事情,例如您可以为可能的光精灵添加闪烁效果。
SKAction *fadeOut = [SKAction fadeAlphaTo:0 duration:.5];
SKAction *fadeIn = [SKAction fadeAlphaTo:1 duration:.5];
SKAction *repeat = [SKAction repeatActionForever:[SKAction sequence:@[fadeOut, fadeIn]]];
SKASpriteLayer *layer = self.map.spriteLayers[2];
[layer runAction:repeat];
SKATiledMap具有自动跟随功能。如果您希望地图定位自己并保持玩家在屏幕上,这是一个很棒的功能。要使用此功能,将autoFollowNode设置为任何SKNode的子类,并在场景的更新方法中调用地图的更新方法。
//showing ease of adding actions to a layer
let fadeOut = SKAction.fadeAlphaTo(0, duration: 2)
let fadeIn = SKAction.fadeAlphaTo(1, duration: 2)
let sequence = SKAction.sequence([fadeOut, fadeIn])
let repeatAction = SKAction.repeatActionForever(sequence)
let backgroundLayer = map.spriteLayers[0]
backgroundLayer .runAction(repeatAction)
在创建你的 Tiled 地图时,如果 SKATiledMap 在瓦片或对象中发现以下属性,它将创建物理体。
SKATiledMap 针对 ignoresSiblingOrder
进行优化。请确保将你的 SKView 设置为 skView.ignoresSiblingOrder = true
。z 位置如下。瓦片层的第 1 层将在 z 位置 0,第 2 层将在 z 位置 1。SKATiledMap 还最大化了绘制调用。你将拥有的绘制调用仅与精灵图的个数相同。
如果您想联系 SKA,请通过电子邮件发送给我们 [email protected]
版权所有 © 2015 Sprite Kit Alliance
特此授予任何获得此软件和相关文档副本(以下简称“软件”)的任何人,免费使用该软件的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本,并允许获得软件的人进行上述行为,前提是遵守以下条件
上述版权声明和本许可声明应包含在软件的副本或实质部分中。
软件按“原样”提供,不提供任何形式的保证,无论是明示的、隐示的,还是关于适销性、特定用途适用性或非侵权的保证。在任何情况下,作者或版权所有者不对任何索赔、损害或其他责任负有责任,不管是在合同行为、侵权行为或其他行为中产生的,无论是由于软件或软件的使用或其它处置引起的。