Jump to content

  • Log In with Google      Sign In   
  • Create Account


Cocos2d-x CCTMXTiledMap Scrolling and Collisions


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 North   Members   -  Reputation: 102

Like
0Likes
Like

Posted 28 November 2012 - 10:18 AM

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

Sponsor:

#2 North   Members   -  Reputation: 102

Like
0Likes
Like

Posted 28 November 2012 - 01:49 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS