I'm currently developing a top down shooter for iOS using the Cocos2d-x framework.
I'm creating levels using the Tiled map editor. I've created and a tiled map that has a size of 320x960.
The tiled map has objects I'd like to shoot on one layer, and another layer has the collision properties around those objects.
When the map is loaded without any scrolling, My collision detection works as expected. When I begin to scroll the tiled map, this is where everything goes wrong.
I have the map stop scrolling when it reaches the end of the map. When the ship is in the second area of the map, doing some debugging, when the ship fires it's lasers, the laser are starting from coordinates (160, 10). They should be starting from approx (160, 480). Because the coordinates are incorrect, the conversion to the tiled map coordinates are also incorrect. The ship and lasers don't seem to know where they are in the world. Any suggestions to point me in the right direction?
Previously, I added the tiled map as a child to the scene, and I was scrolling it normally.
I decided to add it to a CCParallaxNode, and it's this node that I'm scrolling instead, but I get the same issue.
I just wanted to update this thread. I was able to figure out the issue.
For the collision detection, where I convert the laser position to the tilemap position, I needed to add the tileset position as an offset like this:
CCPoint actualLaserPosition = ccpAdd(shipLaser->getPosition(),_tilemap->getPosition());
CCPoint tilept = tileCoordForPosition(actualLaserPosition);
This would then give me the correct tile coordinates for me to cross reference with my collision layer.