开发者

Cocoa control to render a tile map

开发者 https://www.devze.com 2023-03-19 19:46 出处:网络
Is there any Cocoa control that is capable of drawing tile maps with multiple layers and multiple texture sources which can also intercept touches into single tiles? Having multiple layer support is n

Is there any Cocoa control that is capable of drawing tile maps with multiple layers and multiple texture sources which can also intercept touches into single tiles? Having multiple layer support is not a real requirement but an optional feature (the views could still be stacked). Hardware acceleration is not needed at all.

So far I have toyed around with NSMatrix, IKImageBrowser and NSCollectionView but non of them felt like a good solution for the problem. Ideally I need an control similar to the one in Tiled.app. Is开发者_运维百科 there anything, third party or built-in, or do I have to handcraft this control?


I fear that you will be hardly able to find a ready-to-use control for managing tile maps.

If I had to implement something like that on my own, I would consider using CATiledLayer, since this is the closest thing to a tile map control that I know of.

From CATiledLayer Reference:

CATiledLayer is a subclass of CALayer providing a way to asynchronously provide tiles of the layer's content, potentially cached at multiple levels of detail.

There is a nice sample by Bill Dudney (the author of "Core Animation for MacOS and the iPhone"). This sample could provide you a solid foundation for your own project, though it only displays one single PDF, allowing you to zoom in the area you clicked on (this requires rereading the tile at a different detail level).

Another interesting introduction can be found here. This is more step-by-step, so you might start with this.

Finally, on Cocoa is my Girlfriend there is a nice article, although it focuses on iOS, but you may find it anyway relevant.


Cocos2D supports building mac applications now

Article on cocos2d stating this: http://www.cocos2d-iphone.org/archives/1444

Aee here for how to do it: http://chris-fletcher.com/tag/cocos2d-os-x/

Aee here on how to use TMX tile maps with Cocos2D to build tile based maps: http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:tiled_maps

This means you can use the power of Cocos2d and you will have to write much less code to get to where you want with a tile based map.

If you don't want to use Cocos2D:

It seems you would have to code it yourself, but it shouldn't be too hard to do.

First you can create your .TMX file using the tile editor "Tiled.app" then you would need to parse the XML using a standard xml library for Cocoa.

To lay out the tiles use a UIView for the overall container and then create a tile class that holds your tile display information and responds to clicks the tile class should extend UIView. For the tile class allow the assigning of a click delegate and assign your ViewController as the click delegate for all tiles so you can handle clicks easily with the clicked tile being passed to you.

Loop through your xml data and create and position the tiles in the overall UIView by using the tiles width/height and your tilemaps rows/columns.

I think in about a day or 2 you could have the tile map being rendered and clickable using the standard TMX format which will allow you to edit your map in "Tiled.app"

The TMX standard is covered here: https://github.com/bjorn/tiled/wiki/TMX-Map-Format


route-me might fit the bill.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号