问题
I tried cocos2d TileMap sample from here, In this tilecord returned for given player position is wrong.
Here is code
Point HelloWorld::tileCoordForPosition(Point position)
{
int x = position.x / mTileMap->getTileSize().width;
int y = ((mTileMap->getMapSize().height * mTileMap->getTileSize().height) - position.y) / mTileMap->getTileSize().height;
return Point(x, y);
}
Here is Map Screenshot
Also tileCord returned is wrong. So collision is not working. I used it from sample in Ray Wenderlich site
Here is full sample code https://app.box.com/s/whunv70tstwxbgzxdvxfeu080y6gwucb
If anyone has time, then check it and please help me to find bug.
回答1:
In cocos2dx 3.17, spawn points returned is exactly half, same tileMap returns proper value in Cocos2d-ObjC project. So temporary fix is to multiply input value inside tileCoordForPosition by 2. This is temporary solution...still waiting for proper fix.
Point HelloWorld::tileCoordForPosition(Point position)
{
Point newPos = Vec2(position.x*2, position.y*2);
int x = newPos.x / mTileMap->getTileSize().width;
int y = ((mTileMap->getMapSize().height * mTileMap->getTileSize().height) - newPos.y) / mTileMap->getTileSize().height;
return Point(x, y);
}
Here is full working TileMap sample : https://app.box.com/s/r3kglzbx6naig896bq4my7opfeg6ftwz
来源:https://stackoverflow.com/questions/52019991/cocos2dx-3-17-tilemap-basic-sample-wrong-tilecord-position-object-layer-itmes