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学习笔记(19)--label 、label atlas
  • cocos2d-x学习笔记(23)--地图的使用3--CCTMXLayer
  • Cocos2d-x学习(一):HelloWorld
  • cocos2dx在xcode下开发,编译到android上(2)
  • cocos2d 设置屏幕默认方向
  • cocos2d-x学习笔记(22)--地图的使用2(TMX) --Z-Order、AnchorPoi
  • Cocos2d-x 2.0 之 Actions “三板斧” 之一
  • cocos2d-x学习笔记(18)--游戏打包(windows平台)
  • cocos2d-x学习笔记(16)--spritesheet(精灵表单)
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1