I looked at this really quick, the TMX file is ok. It's not obvious what's wrong, I bet it's a rounding/math error. It looks like it's scaling down the tiles somehow when it draws. If you look at it with CCTMXTiledMap you can see the difference.
HKTMXTiledMap(290 posts) (51 voices)
slycrel, yes, I see what it's doing... but no clue why. As I said, I created another 400x400 map with 32x32 tiles, and nary a problem.
I created three new tmx, with different sizes and diferentes tile images, and got similar results (smaller tiles). So is not the original tmx...
I seem to have the same issue as NOG - garbled graphics. TMX is 20x20 with 64x64 squares, displays fine with CCTMXTiledMap...
Testing on iPad with 4.2, same problem on iPhone - both on simulator
Tnx for share @skyhawk!
The link http://hkasoftware.com/fileserve/HKTMXTiledMap.zip died!
Can you re-up in some place, pls? TNX!!
He removed it on purpose since it was outdated. Newest version is here: https://github.com/skyhawk2891/cocos2d-iphone-extensions/tree/HKTMXTiledMap/Extensions/HKTMXTiledMap
tnx andrew! Finally I've found it!
give me good luck! :]
Hi, I'm trying to implement a titled map animation.
I make the tmx map adding the "Next" and "Delay" in each of tile.
Adding the tiledmap on main layer it's showing correctly, but still stopped.
My .tmx contain:
.... <tile id="0"> <properties> <property name="Delay" value="1"/> <property name="Next" value="1"/> </properties> </tile> <tile id="1"> <properties> <property name="Delay" value="1"/> <property name="Next" value="2"/> </properties> </tile> ...
My implementation is very simple:
self.tileMap = [HKTMXTiledMap tiledMapWithTMXFile:@"ocean.tmx"]; self.background = [_tileMap layerNamed:@"OceanSurface"]; [self addChild:_tileMap z:-1];
Where I'm wrong?
can't have a tile id of 0
use http://www.mapeditor.org/ instead of trying to do it by hand
also, with your animation, it would go all tiles 0 would go to tile 1, which would go to tile 2, and if tile 2 has no next, it would stop there.
if you want loop, you need to set the tiles back to the start.
tile 1: next->tile 2
tile 2: next->tile 3
tile 3: next->tile 1
That .tmx is generated by Tiled 0.7.0 and it put gid 0 to first one.
I have all tile with property "Next" setted to next one on the list, and the last one with "Next" = "0" to return to loop, in exactly the same way you describe it.
The only thing I miss is the word "tile", and the property is named with capitalized "Next".
on tile 0: "Next"="1"
on tile 1: "Next"="2"
on tile 2: "Next"="0"
check your tileset declaration. It generally has an attribute like:
So the numbers you are looking at there IIRC are based on that firstgid. Or in other words, the numbers you have listed above are properties based on an atlas (0 being the first tile in the atlas), you need to add the tile set's firstgid to those numbers to get the GID you will be working with.
okkk, I see!
The GID is NOT corresponding to the ID's tile! It's a self-generated number from a "firstgid" value!
In that case corresponding to ID+1
Now my .tmx contains that:
<tile id="0"> <properties> <property name="Delay" value="0.1"/> <property name="Next" value="2"/> </properties> </tile> <tile id="1"> <properties> <property name="Delay" value="0.1"/> <property name="Next" value="3"/> </properties> </tile> <tile id="2"> <properties> <property name="Delay" value="0.1"/> <property name="Next" value="4"/> </properties> </tile> ...
Tnx at all!
Now I'll find to a "randomly generated" grid.
HKTMXTiledMap is compatible with TMXGenerator??
Other than rotation (which itself isn't yet official) and tile flipping, TMXGenerator and HKTMXTiledMap are compatible.
If I don't want to use the TMXGenerator, is there any way to resize the map "on the fly"?
That is: I would like to add a new line (row or column) of tiles to an existing layer, so as to tip it to my "world".
TMX maps aren't really designed to work like this. You may be able to get it to work though I haven't tried. What I ended up doing in my project was using a smaller map and then making multiple TMX maps side by side rather than extending one map.
Ok, I see..
In my case, your solution would be difficult, since the maps are also subject to 3D waves, and it would be complicated to calculate the degree of "bending", etc. ..
I can know the size I need before the map is initialized. You know if I can initialize a new layer with a certain size? I would use the same GID all over the map (then this would change, as all the others are the next frames of the first).
I think that layers don't have to be as big as the overall map, but I think that they are by default. Your biggest concern will be memory probably, followed by speed if you're doing a lot of reassigning of tiles.
Maybe initialize your initial area and then reassign tile GIDs on the fly when your tiles are about to come into view.
memory concerns can certainly be an issue as you get into the tens of thousands of tiles ( eg. 100x100 +) and many layers. Speed will rarely be an issue unless you're assigning 1000s of tiles per frame (which is generally not a smart idea).
Anyways, my suggestion is just try it out. prototype it, play around. don't be afraid to throw away code =)
Can I add a feature request? I've really been wanting to make an isometric game with a massive number of tiles. This is a tutorial I found on doing the next best thing. It works in tiled because I can adjust the tile set tile size and the map tile size independently. When I port it into an hit stiles map it dousnt work with correct spacing. Could you add support for stuff like this? If not I will let you know if I figure it out.
I'm trying to do that:
- in the mapeditor I create a gigant empty map, whit a layer and in that layer y put one tile at 0,0
- then, in the code, I calculate the size I really need and loop around the "involved cell" and set the correct GID.
At the end of the process, I have an empty giant map and the space I need filled from the tile.
The question is: the empty space occupe memory? And if so, occupe the same as if it are full "drawed"?
Do you think this's a "decent" solution?
wanted to try this
download the code from
there was no tileAt message in it? like in the normal CCTMXTileMap
so i tried to add it as best i could... now i get an error
ERROR: Uncaught exception TMX: Only one tileset per layer is supported
i am only using 1 tileset per layer so i don't know what the problem is
has anyone seen this error or know how to fix it?
i also get errors (no map visible) when i try to use it in the TMXGeneratorTest in the Extensions
i think TMX generator does something different with Gids?
has anyone tried this with the TMXGenerator or have any tips on getting them to work together?
thanks a lot
TileAt doesn't make sense in the context of HKTMXTiledMap. TileAt returns a ccsprite. This class does not use ccsprites(part of why cctmxtiledmap is so slow in the first place). What purpose do you need tileAt that tileGIDAt does not accomplish?
I have not tested with the generator, but as long as the generator makes valid maps, that have at least 1 tile per layer ( fix for this should come soon now that I'm done with the contest), then there should be no issues.
i was using tileAt to set and get the color of the tile for lighting, maybe there is a way to do that with GidAt?
no real need for the performance enhancements yet... just need some way to animate
thanks for your help
a solution for your lighting: create a tile set of N stages of lighting (0 alpha to opaque black?)? set it as a layer over your other layers, and then set it based on your lighting levels? doesn't help you if you have colored lighting, that would require more work.
But yes, there is no easy way to work setting "tile" color into HKATMXTiledMap.
I've been playing around with HKTMXTiledMaps this afternoon, plugging them into my game in place of the CCTMXTIledMaps I have been using. So far I've been pleasantly surprised.
My main concern is that there is no support for opacity. I mean, HKTMXLayers have an opacity property, but you don't actually do anything with it. I tried inserting "glColor4ub(255, 255, 255, opacity_);" in place of the glColor4f(1,1,1,1); call you had, but it doesn't actually work. I'm trying to figure out what's different about how you draw the layers that this wouldn't do the trick, but I'm not very good at "raw" opengl, so I'm not sure what to try. If anyone has some pointers, I'm all ears.
I already implemented a "blendFunc" property as I like to use additive blending (along with reduced opacity) on some of my map layers. The glBlendFunc() call works without any problems, which is further confusing me about glColor...
I will need to do some poking around to convert my old tile animation method. I'm probably going to have to customize it as setting up a bunch of tile gid properties seems very impractical given the number of different animations I have.
Thanks a lot for contributing this @skyhawk!
BlueEther, that's great to hear! If you could share the blendFunc, I'd be interested in integrating it back into the main source.
I'll look into the opacity issue. I personally don't use it, but I can definitely see real value in it (and it would actually solve a design issue I've thought about).
Regarding animations, they can be a tad impractical, but I needed it to be strictly data driven, all from within Tiled. Tis was the best way. I'm open to other suggestions, as long as I can create a GID loop, then the animation system will remain fast (it's BLAZINGLY fast considering you can have an entire 400x400 map animate with negligible performance lost)
Also, if you have any screenshots or videos to show off performance or how you're using it (or even the size of the map you're using it for), I'm definitely interested.
I define all my animations for both objects and tiles in XML. I specify which tile gids correspond to which animations using an intermediary file that collects the tiles by the name of their texture. This way every map that uses a given tile texture will share the animations. I also have a way of specifying a "cluster" of animations with a given offset, so if I have a whole set of tiles that animate in the same way as with a coastline or something, I tell it to take all of the tiles in one clump as frame 1, for x number of frames below with a given y offset. I'm probably not explaining it very well. It's very simple in actuality and saves me a lot of set up work. I also take advantage of x/y offsets for some tile animations, essentially creating a 2x2 cluster of the same tile and moving the CGRect for the tile around within that area each frame to create the illusion that they are all moving.
I suppose some of this might be accomplishable using the "external tileset" feature of Tiled, but I've never looked into it because I have my own system that works just as well regardless of whether its an object or a tile.
I'm definitely going to stick with this and make this work, because with CCTMXTiledMaps I get slow loading and performance on my old 2gen iTouch even a 40x40 map, whereas I get fast loading and 60 fps even with a 128x128 map using HKTMXTIledMap! It's really a great class.
Basically it consists of adding a "ccBlendFunc blendFunc_;" variable and corresponding readwrite property.
In the init method, set the default values:
blendFunc_.src = CC_BLEND_SRC; blendFunc_.dst = CC_BLEND_DST;
and in the draw method:
at the beginning:
BOOL newBlend = blendFunc_.src != CC_BLEND_SRC || blendFunc_.dst != CC_BLEND_DST; if(newBlend) glBlendFunc( blendFunc_.src, blendFunc_.dst );
and at the end:
if(newBlend) glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
The code was pretty much lifted verbatim from CCSpriteBatchNode or something (can't remember exactly where I cut it from).
Getting opacity to work wasn't that hard once I remember that use of glColor varies depending on if your textures have premultiplied alpha or not. The code needs to look something like this for premultiplied textures such as mine:
glColor4ub(color_.r*opacity_/255, color_.g*opacity_/255, color_.b*opacity_/255, opacity_);
BTW I've managed to make my animations work with HKTMXLayer, though I had to completely rework the methodology to do so. It works nicely, but its a completely different setup then what you had. Not sure if you're interested in the code. It does use a few utility methods from other files so I can't really just copy and paste the code.
I would be interested in seeing what you concocted together. =)
You must log in to post.