(1)Director类(导演类):
(2)Scene类(场景类):
(3)Layer类(图层类):
(4)Sprite类(精灵类):
//创造精灵
auto sp=Sprite::create("circle.png");
this->setTexture(str);//换图片
1、Menu和MenultemMenu:菜单它是Menultem的容器
Menultem:菜单项
MenultemToggle:可以容纳多个Menultem的子类,点击可以切换下一个显示的按钮。
MenultenImage:Menultem的子类,就是我们平时看到的图片按钮。
MenultemAtlasFont: 我们平时看到的汉字按钮
Menultem的子类有:MenultemLabel、MenultemAtlasFont、MenultemFont、MenultemSprite、Menultenlmage、MenultemToggle
menu->setPosition(Vec2::ZERO);
setCallback 回调函数,用于响应菜单
2、Label(字体):
a)使用系统字体创建auto label=Label::createwithSystemFont(“中泰教育”,“fonts/Marker Felt.ttf”,30);
b)使用BMF字体创建
auto bmfLabel=Label::createwithBMFont(“FontBMFont.fnt”,“植物大战僵尸B2”);
c)使用charmap创建
auto charmapLabel=Label::createwithCharMap(“FontALtas.png”,14,21,48);/宽 高 第一个字符acall码
charmapLabel->setPosition(Vec2(240,160));
charmapLabel->setString(“123456”);
this->addChild(charmaplLabe1);
3、ProgressTimer 进度条的 百分比 Percentage
a)圆周形进度条
auto progressCircle=ProgressTimer::create(Sprite::create(“circle.png”));
progressCircle->setPosition(Vec2(240,160));
this->addChild(progressCircle);
progressCircle->setPercentage(60);//显示百分比
progressCircle->setType(ProgressTimer::Type::RADIAL);//进度条类型
//auto action_1=ProgressFromTo::create(3,0,100);//进度条动作 3秒从0-100
// progressCircle->runAction(action_1);
b)长方形进度条
auto progressLong =ProgressTimer::create(Sprite::create(“Long.png”));
progressLong->setPosition(Vec2(240,160));
progressLong ->setType(ProgressTimer::Type::BAR); //进度条类型
progressLong->setMidpoint(Vec2(0,0.5)); //进度条方向 从0开始
progressLong->setBarChangeRate(Vec2(1,0)); //进度 条 变化率 到(1,0)
progressLong->setPercentage(50);
this->addChild(progressLong);
// auto action_2=ProgressFromTo::create(3,0,100);
// progressLong->runAction(action_2);
LoadingBar进度条 的 百分比(Percent)
我们看到游戏的资源加载界面的进度显示就是通过这个控件完成的。
(人物血量)
auto loadingBar =LoadingBar::create("loadingbar.png");
loadingBar->setPosition(Vec2(240,280));
this->addChild(loadingBar,10);
schedule([=](float dt) {
static int time=1;
if (time>=100)
{
unschedule("loadingbar");
}
time+=10;
loadingBar->setPercent(time);//百分比
},1,"loadingbar");
开启一个时间调度器不断调用updateZT,间隔为0.5s,重复次数为10次,第一次执行会延迟5s
schedule(CC_CALLBACK_1(Helloworld::updateZT,this),0.5,10,5,updateZT”);
schedule([=](float dt) {
static int time=1;
if (time>=100)
{
unschedule("loadingbar");
auto scene =My2::createScene();
Director::getInstance()->pushScene(scene);//入栈
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();//暂停;
}
time+=10;
loadingBar->setPercent(time);
},1,"loadingbar");
Cocos2d-X的动作动作(Action):
(1)动作是对Node以及其子类的操作实现实体,也就是说Node和其子类都可以“执行动作”。
(2)动作具有传递性,当一个节点在做动作,那么它的子节点也会相应的做出该动作,这就是传递,更是符合正常思维。
auto sp=Sprite::create("ball1.jpg");
sp->setPosition(Vec2(160, 240));
this->addChild(sp,10);
auto sp1=RotateBy::create(0.5, 0, 180);
sp->runAction(sp1);
1.1持续动作(ActionInterval):需要一定时间去执行的动作基本动作:
(1)MoveTo和MoveBy //移动位置 移动方向
(2)RotateTo和RotateBy //旋转角度到 //旋转角度
(3)ScaleTo和ScaleBy //比例(放大/缩小) //比例(放大/缩小)
(4)JumpTo和JumpBy 跳跃
(5)Blink//Blinkauto 闪烁
(6)reverse //相反
函数auto _moveBy=MoveBy::create(2,Vec2(100,0));
auto _moveByBack=_moveBy->reverse();
testsp->runAction(_moveByBack);