Cocos2d-x 3.2 大富翁游戏项目开发-第七部分 获取角色路径_2(2)
来源:未知 责任编辑:责任编辑 发表时间:2015-09-09 15:29 点击:次
//根据角色的上下左右四个vector 创建四个方向的动作
Animation * player1_animation_left = Animation::createWithSpriteFrames(player1_anim_left_vector,0.1f);
Animation * player1_animation_right = Animation::createWithSpriteFrames(player1_anim_right_vector,0.1f);
Animation * player1_animation_down = Animation::createWithSpriteFrames(player1_anim_down_vector,0.1f);
Animation * player1_animation_up = Animation::createWithSpriteFrames(player1_anim_up_vector,0.1f);
Animation * player2_animation_left = Animation::createWithSpriteFrames(player2_anim_left_vector,0.1f);
Animation * player2_animation_right = Animation::createWithSpriteFrames(player2_anim_right_vector,0.1f);
Animation * player2_animation_down = Animation::createWithSpriteFrames(player2_anim_down_vector,0.1f);
Animation * player2_animation_up = Animation::createWithSpriteFrames(player2_anim_up_vector,0.1f);
///根据角色的上下左右四个动作 创建四个方向的动画
player1_animate_left = Animate::create(player1_animation_left);
player1_animate_right = Animate::create(player1_animation_right);
player1_animate_down = Animate::create(player1_animation_down);
player1_animate_up = Animate::create(player1_animation_up);
player2_animate_left = Animate::create(player2_animation_left);
player2_animate_right = Animate::create(player2_animation_right);
player2_animate_down = Animate::create(player2_animation_down);
player2_animate_up = Animate::create(player2_animation_up);
}
2、 创建完角色需要的文件后,还需要角色在地图的位置,由于能走的路径都在way图层中,在setWayPassToGrid()方法中,我们把way图层中sprite的坐标保存到wayLayerPass_vector中,这样就可以根据其中的坐标设置角色的位置了
void GameBaseScene::setWayPassToGrid() { TMXLayer* wayLayer = _map->layerNamed(way); Size _mapSize = wayLayer->getLayerSize(); for (int j = 0; j < _mapSize.width; j++) { for (int i = 0; i < _mapSize.height; i++) { Sprite* _sp = wayLayer->tileAt(Point(j, i)); if (_sp) { float x = _sp->getPositionX(); float y = _sp->getPositionY(); int col = x/tiledWidth; int row = y/tiledHeight; canPassGrid[row][col] = true; //取得该位置的坐标,保存到对象wayLayerPass_vector中 Vec2 p = _sp->getPosition(); wayLayerPass_vector.push_back(p); log(canPassGrid row= %d ,col =%d ,canpass = %d ,row,col,canPassGrid[row][col]); } } } log(setWayPassToGrid finished); }
3、 添加的角色我们先封装成一个RicherPlayer类,该类记录角色的信息,包括角色名称、资金、体力、敌友
RicherPlayer* RicherPlayer::create(char* name,SpriteFrame* spriteFrame,bool enemy,int money,int strength) { RicherPlayer* player = new RicherPlayer(); player->init(name,spriteFrame, enemy,money,strength); player->autorelease(); return player; } bool RicherPlayer::init(char* name,SpriteFrame* spriteFrame,bool enemy,int money,int strength) { Sprite::initWithSpriteFrame(spriteFrame); _name = name; _enemy = enemy; _money = money; _strength = strength; return true; }
相关新闻>>
- Cocos2d-x 自定义按钮类控制精灵攻击----之游戏开发《赵云要格斗
- Cocos2d-x 3.2 大富翁游戏项目开发-第七部分 获取角色路径_3
- Cocos2d-x 3.2 大富翁游戏项目开发-第八部分 角色按路径行走
- 结合cocos2d-x开发配置sublime text
- cocos2d-x开发: 如何从项目中分离出接口范例
- cocos2d-x在iOS/Android双平台上嵌入WebView
- Cocos2d-x 3.2 大富翁游戏项目开发-第十部分实现人物轮流行走
- cocos2d-x开发: 一切应该从配置文件读取开始
- 使用python创建cocos2d-x项目
- cocos2d-x 缓存
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>