Cocos2d-x之塔防(二)让怪物跑起来
来源:未知 责任编辑:责任编辑 发表时间:2014-01-26 21:59 点击:次
之前用的版本是2.0.1的版本,后来又用2.1.1重新写了一部分,现在全新开始,就用最新的版本,cocos2d-x-3.0beta,这个版本和之前的相比变化挺大的。
这是用的背景的素材

程序实现方法:
//===========加载背景地图=============
auto bg = TMXTiledMap::create(bg.tmx);
bg->setPosition(Point(0,0));
this->addChild(bg,0);
这样就可以把我们编辑好的地图加载到场景中了,再修改一下bg.tmx文件,记录一下我们的路线。
程序中初始化路线的方法:
auto map = TMXTiledMap::create(bg.tmx);
auto group = map->getObjectGroup(path);
auto& objects = group->getObjects();
for (auto& obj : objects)
{
ValueMap& dict = obj.asValueMap();
int x = dict[x].asInt();
int y = 480 - dict[y].asInt();
wayPoint.push_back(Point(x,y));
wayCount++;
}
容器wayPoint记录tmx文件中的点。
好了,现在背景有了,路线也有了,接下来就是怪物了。
怪物的素材图

读取方法:
void Enemy::uploadEnemy()
{
//RightMove()
VectortempRightMove;
for (int i = 8; i < 12; i++)
{
tempRightMove.pushBack(Myframes[i]);
}
Animation* aniRightMove = Animation::createWithSpriteFrames(tempRightMove,0.2f);
actionRightMove = Animate::create(aniRightMove);
actionRightMove->retain();
//LeftMove()
VectortempLeftMove;
for (int i = 4; i < 8; i++)
{
tempLeftMove.pushBack(Myframes[i]);
}
Animation* aniLeftMove = Animation::createWithSpriteFrames(tempLeftMove,0.2f);
actionLeftMove = Animate::create(aniLeftMove);
actionLeftMove->retain();
//UpMove()
VectortempUpMove;
for (int i = 12; i < 16; i++)
{
tempUpMove.pushBack(Myframes[i]);
}
Animation* aniUpMove = Animation::createWithSpriteFrames(tempUpMove,0.2f);
actionUpMove = Animate::create(aniUpMove);
actionUpMove->retain();
//DownMove()
VectortempDownMove;
for (int i = 0; i < 4; i++)
{
tempDownMove.pushBack(Myframes[i]);
}
Animation* aniDownMove = Animation::createWithSpriteFrames(tempDownMove,0.2f);
actionDownMove = Animate::create(aniDownMove);
actionDownMove->retain();
}
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 进入详细评论页>>

![cocos2d_x+lua[2]](/uploads/allimg/131030/110J64609-0-lp.jpg)








