我尝试从此处,在给定玩家位置返回的此tilecord中,错误.
I tried cocos2d TileMap sample from here, In this tilecord returned for given player position is wrong.
这是代码
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); }这里是地图截图
返回的tileCord也错误.因此碰撞不起作用.我从Ray Wenderlich网站的示例中使用了它
Also tileCord returned is wrong. So collision is not working. I used it from sample in Ray Wenderlich site
这里是完整的示例代码 app.box/s/whunv70tstwxbgzxdvxfeu080y6gwucb
Here is full sample code app.box/s/whunv70tstwxbgzxdvxfeu080y6gwucb
如果有人有时间,请检查一下,请帮助我查找错误.
If anyone has time, then check it and please help me to find bug.
推荐答案在cocos2dx 3.17中,返回的生成点正好是一半,相同的tileMap在Cocos2d-ObjC项目中返回正确的值.因此,临时解决方案是将tileCoordForPosition中的输入值乘以2.这是临时解决方案……仍在等待正确的解决方案.
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); }以下是完整的TileMap示例: app.box/s/r3kglzbx6naig896bq4my7opfeg6ftw/a>
Here is full working TileMap sample : app.box/s/r3kglzbx6naig896bq4my7opfeg6ftwz
更多推荐
Cocos2dx 3.17 TileMap Basic Sample
发布评论