Cocos2dx 3.17 TileMap Basic Sample

编程入门 行业动态 更新时间:2024-10-26 00:30:15
本文介绍了Cocos2dx 3.17 TileMap Basic Sample-错误的tilecord位置,返回的对象层itmes位置也错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试从此处,在给定玩家位置返回的此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

本文发布于:2023-11-27 01:41:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636055.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Cocos2dx   TileMap   Sample   Basic

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!