Guys, can i ask for ideas? how would you handle a collision detection with tile map?
i have created platforms and should make them unwalkable tiles. is their a way to set these tiles to become unwalkable?
A fast, easy to use, free, and community supported 2D game engine
Guys, can i ask for ideas? how would you handle a collision detection with tile map?
i have created platforms and should make them unwalkable tiles. is their a way to set these tiles to become unwalkable?
Personally I created some special tiles at the begining of my tileset ( since there could be not only tiles that you can't walk through, but ones you can walk on but jump up through, ones that damage you, etc ). I created a layer in my TMX to put those on, then turned off the visibility of the layer when I saved it.
I modified TMXTileMap to still load the layer if it's not visible but set the visibility of the layer to be hidden. Then I can still get at the layer and use tileGIDAt.
For me it makes it easier to only have to check against one GID for each possible *type* of tile, than each individual tile that could *be* that type.
oh. sounds cool. :D thank you.
how did you modify your TMXTileMap to load invisible layerS?
Look in TMXTiledMap for the initWithTMXFile method ( around line 553 ) - there is a block to skip loading the layer if it's not visible. Comment out that if block and add in a line to set the visibility of the layer, so the block looks like this:
for( TMXLayerInfo *layerInfo in mapInfo.layers ) {
//if( layerInfo.visible ) {
id child = [self parseLayer:layerInfo map:mapInfo];
[child setVisible:layerInfo.visible];
[self addChild:child z:idx tag:idx];
// update content size with the max size
CGSize childSize = [child contentSize];
CGSize currentSize = [self contentSize];
currentSize.width = MAX( currentSize.width, childSize.width );
currentSize.height = MAX( currentSize.height, childSize.height );
[self setContentSize:currentSize];
idx++;
//}
}
The changed items are the commented start / close of the if block and the [child setVisible:layerInfo.visible]; addition.
I typically create a layer ( called something like "walkables" ) in my TMX that then has it's visibility turned off before I save it and can get the tileGID using something like this:
TMXLayer *layer = [mymap layerNamed:@"walkables"];
if ( [layer tileGIDAt:ccp( x, y )] != 1 ) { // walkable tile
Hope that helps =)
wow. thank you! now i finally understood it.
thx exorcyze
Cocos2D 0.9.0 has implemented Tiled's object layers, I'd recommend them instead of this method. Neophyte posted the patch and riq applied it to trunk a few weeks ago. I've been using it since.
I applied the awesome patch for object layers in 0.8.2 and have been using that to set spawn points, collectable positions, enemies, etc. It has been simply invaluable, imo.
I guess it didn't seem like the solution ( to me ) for determining tile types though, since it's not like taking a brush and painting the areas appropriately. Placing an object and setting it's properties for every single tile that could be non-walkable, landable, harmful, etc seemed ineffecient and not really what the "objects" layers were for to me. =)
Depends on how you look at it I guess. I like to create an object called TileProperties per tile so that individual tiles can have different properties (e.g. walkable). I prefer that to using an image to indicate something that doesn't really have a rendering. One thing I will admit, though, is that tiled's interface for bulk creating a lot of similar objects is really lacking. I'm going to be enhancing tiled to have a palette of objects that you can "paint" into an object layer.
Hello,
I have a tilemap and set of tiles, how can i make edges for each tile in tileset. The idea is to build map with ready properties of every tile in tileset. Is there any way to do this?
Thanks.
Has anyone got a source code on a test map using the object layer? I'd love to mess around with it like that.
You must log in to post.