Cocos2dx 3.17 TileMap Basic Sample - wrong tilecord position, object layer itmes position returned also wrong

孤街醉人 提交于 2019-12-10 11:33:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!