Cocos2d-x 3.2 Menu菜单的创建

前端之家收集整理的这篇文章主要介绍了Cocos2d-x 3.2 Menu菜单的创建前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//GameScene.h
#include"cocos2d.h"
class GameScene: public cocos2d::Layer
{
:
static cocos2d::Scene*createScene();
virtual bool init();
void menuCallback(cocos2d::Ref*pSender);
CREATE_FUNC(GameScene);
};



?
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//GameScene.cpp
#include"GameScene.h"
USING_NS_CC;
cocos2d::Scene*GameScene::createScene()
{
auto scene=Scene::create(); //创建一个场景
layer=GameScene::create(); //创建一个图层
scene->addChild(layer);
return scene;
}
//初始化当前的图层
GameScene::init()
{
if (!Layer::init()) //初始化父类
return false ;
//获取屏幕大小
SizevisibleSize=Director::getInstance()->getVisibleSize();
//autosize=Director::getInstance()->getWinSize();
//添加一个图片精灵
sprite=Sprite::create( "OnePiece_1.png" );
sprite->setPosition(Vec2(visibleSize.width/2,visibleSize.height/2));
this ->addChild(sprite);
//创建菜单
//方法
label=Label::createWithSystemFont( "Jacedy" , "MarkerFelt" item1=MenuItemLabel::create(label,CC_CALLBACK_1(GameScene::menuCallback, ));
item1->setPosition(Vec2(visibleSize.width*0.9,visibleSize.height*0.8));
//方法
item2=MenuItemFont::create( ));
item2->setPosition(Vec2(visibleSize.width*0.9,visibleSize.height*0.7));
@H_118_403@
//方法
sprite1=Sprite::create( "btn-play-normal.png" );
sprite2=Sprite::create( "btn-play-selected.png" );
item3=MenuItemSprite::create(sprite1,sprite2,monospace!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:1em!important; min-height:inherit!important">));
item3->setPosition(Vec2(visibleSize.width*0.9,visibleSize.height*0.6));
//方法
item4=MenuItemImage::create( ));
item4->setPosition(Vec2(visibleSize.width*0.9,visibleSize.width*0.5));
menu=Menu::create(item1,item2,item3,item4,NULL);
menu->setAnchorPoint(Vec2::ZERO);
menu->setPosition(Vec2::ZERO);
->addChild(menu);
true ;
}
GameScene::menuCallback(cocos2d::Ref*pSender)
{
}
原文链接:https://www.f2er.com/cocos2dx/344233.html

猜你在找的Cocos2d-x相关文章