Jump to content
  • Advertisement
Sign in to follow this  
North

Cocos2d-x CCTMXTiledMap Scrolling and Collisions

This topic is 2002 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Everyone,
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?

Further details:
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.

Regards,
North

Share this post


Link to post
Share on other sites
Advertisement
Hi Everyone,
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!