一、创建文件~

MainMenuScene.h   MainMenuScene.cpp   MainMenuLayer.h   MainMenuLayer.cpp

那个场景的搭建就不多说了,那个我的打飞机还有别踩白块的学习笔记里有~

二、How to do?

1、initBackground(),创建背景~

(1)在init中先获得屏幕的大小,还有加入图片进入缓存

visibleSize = Director::getInstance()->getVisibleSize();
origin = Director::getInstance()->getVisibleOrigin(); //add texture to cache
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("MainMenu/UI_GameMenuText_cn-hd.plist");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("MainMenu/UI_GameStartMenuLayer-hd.plist");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("MainMenu/FishActor-Small-hd.plist");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("MainMenu/FishActor-Marlin-hd.plist");

(2)实现方法~

void MainMenuLayer::initBackground()
{
//set background
auto ui_background = Sprite::create("MainMenu/ui_background_normal-hd.png");
ui_background->setAnchorPoint(Vec2::ZERO);
ui_background->setPosition(Vec2::ZERO);
this->addChild(ui_background); //Set game logo
auto ui_Logo = Sprite::create("MainMenu/main_ui_title_cn-hd.png");
ui_Logo->setPosition(Vec2(visibleSize.width / 2.0f, visibleSize.height / 1.35f));
this->addChild(ui_Logo, );
}

记得最后要加入到init里面去哦~

(3)效果图~

2、加入按钮~

(1)方法实现~

//Create the start button of the game
auto startGameBtn = Sprite::createWithSpriteFrameName("ui_button_box02_02.png");
auto startGameBtnPush = Sprite::createWithSpriteFrameName("ui_button_box02_01.png");
auto startGameFont = Sprite::createWithSpriteFrameName("ui_2p_010.png"); //Create the scene choose button
auto sceneChooseBtn = Sprite::createWithSpriteFrameName("ui_button_box01_02.png");
auto sceneChooseBtnPush = Sprite::createWithSpriteFrameName("ui_button_box01_01.png");
auto sceneChooseFont = Sprite::createWithSpriteFrameName("button_other_014.png"); //Create the menu
auto startGameMenuItem = MenuItemSprite::create(startGameBtn, startGameBtnPush, CC_CALLBACK_1(MainMenuLayer::startGameEvent, this));
auto sceneChooseMenuItem = MenuItemSprite::create(sceneChooseBtn, sceneChooseBtnPush, CC_CALLBACK_1(MainMenuLayer::sceneChoose, this));
sceneChooseMenuItem->setPosition(Point(startGameMenuItem->getPosition().x, startGameMenuItem->getPosition().y - ));
auto startGameMenu = Menu::create(startGameMenuItem, sceneChooseMenuItem, NULL); //Set the posiiton of menu
startGameMenu->setPosition(Point(visibleSize.width / 2.0f, visibleSize.height / 1.35f-));
startGameFont->setPosition(Point(visibleSize.width / 2.0f, visibleSize.height / 1.35f-));
sceneChooseFont->setPosition(Point(visibleSize.width / 2.0f, visibleSize.height / 1.35f-)); //Add the menu into the scene
this->addChild(startGameMenu, );
this->addChild(startGameFont, );
this->addChild(sceneChooseFont, );

(2)效果图~

3、加入泡泡~

(1)粒子效果的加入~

ParticleSystemQuad* MainMenuLayer::createPaopao(Vec2 position)
{
//Create the paraticle of bubble
auto paopao = ParticleSystemQuad::create("MainMenu/lizhi_qipao.plist"); //Set the bubble position type form the ground
paopao->setPositionType(ParticleSystemQuad::PositionType::RELATIVE); paopao->setPosition(position);
paopao->setScale(2.0f); return paopao;
}

在这里大家看到粒子特效的文件是已经完成的,存在一个plist文件里面而已,所以我们以后可以通过一些辅助的软件进行制作,

(2)创建泡泡

void MainMenuLayer::initBubble()
{
auto paopaoLeft = createPaopao(Vec2(, ));
this->addChild(paopaoLeft, ); //Create the bubble on the lower right corner
auto paopaoRight = createPaopao(Vec2(visibleSize.width, ));
this->addChild(paopaoRight, );
}

(3)上效果图

4、上鱼群~

(1)鱼群的动作的创建~

a.一群小鱼~

ActionInterval* MainMenuLayer::createFishMoveAction(FishActor *fish)
{ //Let the matrix of fishes move back and forth
return RepeatForever::create(
Sequence::create(
MoveTo::create(, Point(fish->getPositionX() - , fish->getPositionY())), CallFunc::create(CC_CALLBACK_0(MainMenuLayer::turnBack, this, fish)),
MoveTo::create(, Point(fish->getPositionX() + , fish->getPositionY())), CallFunc::create(CC_CALLBACK_0(MainMenuLayer::turnBack, this, fish)), NULL));
}
void MainMenuLayer::turnBack(Node* sender)
{ if (sender->getRotation() == 0.0f)
{ sender->setRotation(180.00f);
}
else
{ sender->setRotation(0.00f);
}
}

上面就是创建一个鱼从右游到左,再从左移到右的动画~

b、大鱼

大鱼的动画就是看到的只有从左到右~

ActionInterval* MainMenuLayer::createMarlinMoveAction(MarlinsFishActor *fish)
{ //Let the marlin fis move behind the matrix of fishes
return RepeatForever::create(
Sequence::create(
MoveTo::create(, Point(fish->getPositionX() - , fish->getPositionY())), CallFunc::create(CC_CALLBACK_0(MainMenuLayer::marlinTurnBack, this, fish)),
MoveTo::create(, Point(fish->getPositionX() + , fish->getPositionY())), CallFunc::create(CC_CALLBACK_0(MainMenuLayer::marlinTurnBack, this, fish)), NULL));
}
void MainMenuLayer::marlinTurnBack(Node *sender)
{ if (sender->getRotation() == 0.0f)
{ sender->setVisible(true);
sender->setRotation(180.00f);
}
else
{ sender->setVisible(false);
sender->setRotation(0.00f);
}
}

(2)上鱼群

void MainMenuLayer::fishActorsInital()
{ //Create fishes
for (int fishIndex = ; fishIndex < ; fishIndex++) {//同种类鱼的条数 auto smallFishActor = FishActor::createWithType(FishActor::FishActorType::SmallFish);
auto angelFishActor = FishActor::createWithType(FishActor::FishActorType::AngelFish);
auto croakerFishActor = FishActor::createWithType(FishActor::FishActorType::Croaker);
auto amphiprionFishActor = FishActor::createWithType(FishActor::FishActorType::Bream);
auto breamFishActor = FishActor::createWithType(FishActor::FishActorType::SmallFish); //Set the position of the fishes like a matrix
smallFishActor->setPosition(Vec2( - visibleSize.width / * (fishIndex + ), visibleSize.height / ));
angelFishActor->setPosition(Vec2( - visibleSize.width / * (fishIndex + ), visibleSize.height / * ));
croakerFishActor->setPosition(Vec2( - visibleSize.width / * (fishIndex + ), visibleSize.height / * ));
amphiprionFishActor->setPosition(Vec2( - visibleSize.width / * (fishIndex + ), visibleSize.height / * ));
breamFishActor->setPosition(Vec2( - visibleSize.width / * (fishIndex + ), visibleSize.height / * )); smallFishActor->runAction(createFishMoveAction(smallFishActor));
angelFishActor->runAction(createFishMoveAction(angelFishActor));
croakerFishActor->runAction(createFishMoveAction(croakerFishActor));
amphiprionFishActor->runAction(createFishMoveAction(amphiprionFishActor));
breamFishActor->runAction(createFishMoveAction(breamFishActor)); //Add the fishes into the scene
this->addChild(smallFishActor, );
this->addChild(angelFishActor, );
this->addChild(croakerFishActor, );
this->addChild(amphiprionFishActor, );
this->addChild(breamFishActor, );
} auto marlin = FishActor::createWithType(FishActor::FishActorType::MarlinsFish);
marlin->setVisible(false);
marlin->setPosition(Vec2(, visibleSize.height / ));
marlin->runAction(MainMenuLayer::createMarlinMoveAction((MarlinsFishActor*)marlin));
this->addChild(marlin, );
}

(3)上效果图~

cocos2dx游戏开发——捕鱼达人mini版学习笔记(二)——MainMenu的搭建的更多相关文章

  1. cocos2dx游戏开发——捕鱼达人mini版学习笔记(一)——FishAchor的搭建

    一.创建文件· FishAchor.h还有FishAchor.cpp. 主要就是创建每种鱼的类,方便以后的取用~,很多是重复性的操作,然后我们是mini版,暂时也就加入大概6钟鱼就好= =,然后我们现 ...

  2. 《Cocos2d-x游戏开发实战精解》学习笔记4--实战一个简单的钢琴

    上一节学习了使用Cocos2d-x播放音乐的方法,但是那种方法一般只适合于播放较大的音乐,而一般比较短小的音乐(如游戏中的打斗.按键音效等)则要通过playEffect来播放.本节使用该方法以及之前学 ...

  3. 《Cocos2d-x游戏开发实战精解》学习笔记3--在Cocos2d-x中播放声音

    <Cocos2d-x游戏开发实战精解>学习笔记1--在Cocos2d中显示图像 <Cocos2d-x游戏开发实战精解>学习笔记2--在Cocos2d-x中显示一行文字 之前的内 ...

  4. 《Cocos2d-x游戏开发实战精解》学习笔记1--在Cocos2d中显示图像

    Cocos2d-x中的图像是通过精灵类来显示的.在Cocos2d-x中游戏中的每一个角色.怪物.道具都可以理解成是一个精灵,游戏背景作为一种特殊的单位将其理解成是一个精灵也没有什么不妥.在源文件本章目 ...

  5. cocos2dx游戏开发——别踩白块学习笔记(二)——经典模式的实现

    一.创建GameScene以及GameLayer 就是简单创建一个Scene而已,在此就不多说啦~,可以参照我的打飞机的学习笔记(2). 二.添加一个开始栏 很简单,就是调用Block中的create ...

  6. 《Cocos2d-x游戏开发实战精解》学习笔记2--在Cocos2d-x中显示一行文字

    在Cocos2d-x中要显示文字就需要用到Label控件.在3.x版本的Cocos2d中,舍弃了之前版本所使用的LabelTTF.LabelAtlas.LabelBMFont 3个用于显示文字的类,而 ...

  7. cocos2dx游戏开发——别踩白块学习笔记(一)——Block类

    一.Block类介绍 当然啦,Block类在这个游戏里就是必需品= =,因为整体都是由这个搞出来的,所以我们可以把游戏需要实现的功能都放在这里. 主要有下面这些功能(经典模式): 1.创建一个Bloc ...

  8. 【原】Learning Spark (Python版) 学习笔记(二)----键值对、数据读取与保存、共享特性

    本来应该上周更新的,结果碰上五一,懒癌发作,就推迟了 = =.以后还是要按时完成任务.废话不多说,第四章-第六章主要讲了三个内容:键值对.数据读取与保存与Spark的两个共享特性(累加器和广播变量). ...

  9. PMBOK(第五版)学习笔记二-十大知识领域(P87)

    五大项目管理过程组:启动.规划.执行.监控.收尾过程组 十大知识领域是:项目整合管理.项目范围管理.项目时间管理.项目成本管理.项目质量管理.项目人力资源管理.项目沟通管理.项目风险管理.项目采购管理 ...

随机推荐

  1. 网站的PV,UV,IP名词解释

    PV:PV 是Page Views的缩写,即页面浏览量,用户每一次对网站中的每个网页访问均被记录一次.注意,访客每刷新一次页面,pv就增加一次. UV:UV是Unique Visitor的缩写,即独立 ...

  2. 导入安全证书到jdk步骤详细说明-原

    一.首先要在浏览器打开需要证书的网站,然后把证书下载下来,保存的证书名称随意命名,只要保证唯一性(这个唯一性下文有解释) 二.然后把证书复制到%JAVA_HOME%/jre/bin/路径下,即保证证书 ...

  3. [Asp.Net]状态管理(ViewState、Cookie)

    简介 HTTP协议是无状态的.从客户端到服务器的连接可以在每个请求之后关闭.但是一般需要把一些客户端信息从一个页面传送给另一个页面. 无状态的根本原因是:浏览器和服务器使用Socket通信,服务器将请 ...

  4. <转载>NPOI Excel 单元格背景颜色对照表

    我转载地址:http://www.holdcode.com/web/details/117 NPOI Excel 单元格颜色对照表,在引用了 NPOI.dll 后可通过 ICellStyle 接口的 ...

  5. Bookshelf 2

    Bookshelf 2 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit  ...

  6. CloudPlatform和CloudStack的关系

    The Scalr team is at the CloudStack Collab Conf, and this post summarizes a few things we learned. C ...

  7. ADF成长记1--认识ADF

    2014-07-08 近段时间由于公司项目需要,开始接触Oracle ADF.都说有事没事,上百度,但是对于IT技术而言,上百度还真是不一定好使,至于谷歌嘛,很不巧的进不去了.不过网上ADF的资料当真 ...

  8. linux tar文件解压

    把常用的tar解压命令总结下,当作备忘: tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个, ...

  9. zb的生日

    http://acm.nyist.net/JudgeOnline/problem.php?pid=325 zb的生日 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 ...

  10. 关于Linux下进程间使用共享内存和信号量通信的时的编译问题

    今天在编译一个使用信号量实现进程同步时,出现了库函数不存在的问题.如下图 编译结果实际上是说,没include相应的头文件,或是头文件不存在(即系统不支持该库函数) 但我man shm_open是可以 ...