I’m currently making a Space Shooter game. I’m using a TMX Map for the level design.
When I load the TMX Map (without scrolling), I can detect collision on the collision layer no problem. The problem occurs when I begin to have the map scroll.
I don’t think I’m converting the coordinate for the detection appropriately. If anyone could point me in the right direction, it would be a big help.
Here’s the code for moving the map (CCTMXTileMap object) located in my update method:
CPoint backgroundScrollVert = ccp(0,
Here’s method to convert the laser position to the tilemap position
int x = position.x / *tileMap~~>getTileSize.width;
int y = *tileMap~~>getMapSize.height~~ .height);
Here’s the code for the collision detection:
CCSpriteshipLaser = itLaser;
CCPoint tilept = tileCoordForPosition);
int tileGid =*meta~~>tileGIDAt; //get tile id from collision layer
CCDictionary *props =*tileMap~~>propertiesForGID;
Did some debugging. I have some interesting numbers. Now my ship is static, always floating at the bottom of the screen. The map size is 320 x 960. When the tilemap gets to the end and stops, and the ship shoots it’s lasers,
the laser coordinates are still reading as if they’re starting at the bottom center of the screen (160, 10) as opposed to being (160, 480). Since the coordinates are read as that, then when they get converted to the tilemap coordinates, they’re incorrect, because we already passed those points on the tilemap. This is certainly not a fix, but a step in the right direction. I believe the viewport coordinates are not properly being updated. Any suggestions?