Cocos2D-x游戏开发之十九:瓦块地图之碰撞检测

2023-11-06

昨天我们有了精灵和背景,并且精灵可以跑动了,但是我们不能让精灵无穷无尽地跑下去吧,于是今天我们要在地图上添加一些障碍物了;

首先打开精灵的TMX地图,然后我们自定义一个32X32像素的图片添加到图层中,然后设置此图层的属性为:“collidable” 值为“true”,下一步在地图中新建一个图层起名为“meta”现在发挥你的创造性把这些小东西添加此图层中保存即可。

接下来就该在code中做一些操作了,打开我们的Player类:

class Player :	public Entity
{
public:
	Player(void);
	~Player(void);
public:
	CREATE_FUNC(Player);
	virtual bool init();
	void run();
	virtual bool SetPlayerPosition(int x,int y) ;
	void SetViewPointByPosition();
	CCTMXTiledMap *m_map;
	void SetTMXTileMap(CCTMXTiledMap *map);
	CCTMXLayer *meta;
	CCPoint tileCoordForPosition(CCPoint point);
};

Player::Player(void)
{
}


Player::~Player(void)
{
}
bool Player::init()
{
	
	return true;
}
void Player::run()
{
CCSpriteFrameCache * freamCache = CCSpriteFrameCache::sharedSpriteFrameCache();
freamCache->addSpriteFramesWithFile("run.pl
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Cocos2D-x游戏开发之十九:瓦块地图之碰撞检测 的相关文章

随机推荐