I’ve got an Isometric 10x10 TileMap, with each tile being 132x132. The TMXTiledMap is added directly to the base layer, and I’m looking to be able to tap on a tile and change it to another.
The problem is that when I touch any tile along the right, cocos asserts because the tile_pos is too large. If I tap the leftmost tile, it works out to 3,2, and the other to the top right of it is 3,1. I can’t make sense of the logic here.
Right now, I’m assuming that the camera won’t change, and neither will the map’s position on the screen, but I plan on working on that next.
Here’s how the tilemap looks on the screen before any touching happens, if it helps any.
Thanks, this works pretty well. I’ll need to check out the related discussions to see how to fine tune this. Seems like its offset by about half vertically, where the tile doesn’t register a click until you’re passed the center point.
Oh yeah. There’s often a half tile offset with touch or world positions. There’s also often an off by one Y tile coord. Also tile coord from various tiled types (objects, etc) require map height - y + 1 or similar. Hopefully this code got you close and you find tweaking it to perfection not difficult.
I’m sure I could find our supplemental code in various circumstances where we tweak it.
I’ll keep those in mind because I think I’ll be dealing with all that very soon. I don’t think offsetting it will be too tricky. Getting to be able to pan the map around should only be a matter of offsetting the isox and y by the panned position.
It seems like this->convertToNodeSpace(world_pos) works the same way, where it offsets the world pos to wherever the map’s pos is, given that map is a direct child of this.
Still trying to figure the offset business though.
Haha, yeah there’s so many little helper functions. The source for convertToNodeSpace gets into some math that’s a little too much for me right now, so I’m going to assume it’s accounting for a lot. Thanks a lot for your help.
Man, there’s even a helper for convertTouchToNodeSpace which takes a Touch* and then getLocation on it, and saves you even another step lol.