Introduction to Regular Widgets

We introduced the basic usage of Button before to control a display content of Text. ImageView is easy to use,and GUI also provides us some other useful widgets such as CheckBox and Slider etc.

Text Button

In C++:

 
 
1
2
3
4
5
6
7
    Button* textButton = Button::create();
    textButton->setTouchEnabled(true);
    textButton->loadTextures("cocosgui/backtotopnormal.png","cocosgui/backtotoppressed.png","");
    textButton->setTitleText("Text Button");
    textButton->setPosition(Point(widgetSize.width / 2.0f,widgetSize.height / 2.0f));
    textButton->addTouchEventListener(this,toucheventselector(UITextButtonTest::touchEvent));        
    this->addChild(textButton);

In Lua:

 
 
1
2
3
4
5
6
7
    local textButton = ccui.Button:create()
    textButton:setTouchEnabled(true)
    textButton:loadTextures("cocosui/backtotopnormal.png","cocosui/backtotoppressed.png","")
    textButton:setTitleText("Text Button")
    textButton:setPosition(cc.p(widgetSize.width / 2.0,widgetSize.height / 2.0))
    textButton:addTouchEventListener(touchEvent)        
    self._uiLayer:addChild(textButton)

As button,it has to support touch event. Then call loadTextures method to load image. Notice the third parameter is the display image when button is disabled. Let's focus on the fourth parameter,checking out following method's prototype:

void loadTextures(const char* normal,const char* selected,const char* disabled,TextureResType texType = TextureResType::LOCAL);

The last parameter is image type,default as TextureResType::LOCAL,which means using normal image. On the other hand,the other TextureResType::PLIST is using the resource from plist,and this decide to use Sprite or SpriteFrame creating displaying sprite. We can also use squared picture,remember setting Size.

In C++:

 
 
1
2
3
4
5
6
7
8
9
    UIButton* textButton = UIButton::create();
    textButton->setTouchEnabled(true);
    textButton->setScale9Enabled(true);
    textButton->loadTextures("cocosgui/button.png","cocosgui/buttonHighlighted.png","");
    textButton->setSize(Size(180,textButton->getContentSize().height * 1.5f));
    textButton->setTitleText("Text Button scale9 render");
    textButton->setPosition(Point(widgetSize.width / 2.0f,toucheventselector(UITextButtonTest::touchEvent));        
    m_pUiLayer->addWidget(textButton);

In Lua:

 
 
1
2
3
4
5
6
7
8
9
  local textButton = ccui.Button:create()
    textButton:setTouchEnabled(true)
    textButton:setScale9Enabled(true)
    textButton:loadTextures("cocosui/button.png","cocosui/buttonHighlighted.png","")
    textButton:setContentSize(cc.size(180,textButton:getVirtualRendererSize().height * 1.5))
    textButton:setTitleText("Text Button scale9 render")
    textButton:setPosition(cc.p(widgetSize.width / 2.0,widgetSize.height / 2.0))
    textButton:addTouchEventListener(touchEvent)        
    self._uiLayer:addChild(textButton)

CheckBox

We also see a widget in web page-checkBox,it allows you choose more than one item.

In C++:

 
 
1
2
3
4
5
6
7
8
9
10
    CheckBox* checkBox = CheckBox::create();
    checkBox->setTouchEnabled(true);
    checkBox->loadTextures("cocosgui/check_Box_normal.png","cocosgui/check_Box_normal_press.png","cocosgui/check_Box_active.png","cocosgui/check_Box_normal_disable.png","cocosgui/check_Box_active_disable.png");
    checkBox->setPosition(Point(widgetSize.width / 2.0f,widgetSize.height / 2.0f));
    checkBox->addEventListener(CC_CALLBACK_2(UICheckBoxTest::selectedEvent),this);
    this->addWidget(checkBox);

In Lua:

 
 
1
2
3
4
5
6
7
8
9
10
11
12
 local checkBox = ccui.CheckBox:create()
    checkBox:setTouchEnabled(true)
    checkBox:loadTextures("cocosui/check_Box_normal.png","cocosui/check_Box_normal_press.png","cocosui/check_Box_active.png","cocosui/check_Box_normal_disable.png","cocosui/check_Box_active_disable.png")
    checkBox:setPosition(cc.p(widgetSize.width / 2.0,widgetSize.height / 2.0))

    checkBox:addEventListener(selectedEvent)  

    self._uiLayer:addChild(checkBox)

There are not too much properties in here,but many images loaded-two status images,two disabled status images and pressed image. These five images build a checkBox,setting callback method by addEventListener:

In C++:

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void UICheckBoxTest::selectedEvent(Ref* pSender,CheckBox::EventType type)
{
    switch (type)
    {
        case CheckBox::EventType::SELECTED:
            _displayValueLabel->setString(String::createWithFormat("Selected")->getCString());
            break;

        case CheckBox::EventType::UNSELECTED:
            _displayValueLabel->setString(String::createWithFormat("Unselected")->getCString());
            break;

        default:
            break;
    }
}

In Lua:

 
 
1
2
3
4
5
6
7
local function selectedEvent(sender,eventType)
        if eventType == ccui.CheckBoxEventType.selected then
            self._displayValueLabel:setString("Selected")
        elseif eventType == ccui.CheckBoxEventType.unselected then
            self._displayValueLabel:setString("Unselected")
        end
    end  

There are two statuses for a checkBox-selected and unselected. It changes its status when it is touched,we can call some callback functions to do something. As shown,when the status changed,it will call the function to inform the checkBox.

Slider

It's a good choice to choose slider if you want to add a widget controlling the volume.

In C++:

 
 
1
2
3
4
5
6
7
8
9
10
11
 // Create the slider
        Slider* slider = Slider::create();
        slider->loadBarTexture("cocosui/sliderTrack2.png");
        slider->loadSlidBallTextures("cocosui/sliderThumb.png","cocosui/sliderThumb.png","");
        slider->loadProgressBarTexture("cocosui/slider_bar_active_9patch.png");
        slider->setScale9Enabled(true);
        slider->setCapInsets(Rect(0,0,0));
        slider->setContentSize(Size(250.0f,19));
        slider->setPosition(Vec2(widgetSize.width / 2.0f,widgetSize.height / 2.0f/* + slider->getSize().height * 3.0f*/));
        slider->addEventListener(CC_CALLBACK_2(UiSliderTest_Scale9::sliderEvent,this));
        _uiLayer->addChild(slider);

In Lua

 
 
1
2
3
4
5
6
7
8
9
local slider = ccui.Slider:create()
    slider:setTouchEnabled(true)
    slider:loadBarTexture("cocosui/sliderTrack.png")
    slider:loadSlidBallTextures("cocosui/sliderThumb.png","")
    slider:loadProgressBarTexture("cocosui/sliderProgress.png")
    slider:setPosition(cc.p(widgetSize.width / 2.0,widgetSize.height / 2.0))
    slider:addEventListener(percentChangedEvent)

    self._uiLayer:addChild(slider)

We take different ways to load images,loadBarTexture for slider background image and loadSlidBallTextures for three statuses image of slider. That is the center ball can be dragged. However,loadProgressBarTexture method displaying the progress of the slider. It also has callback function,which can be used for record current status:

In C++:

 
 
1
2
3
4
5
6
7
8
9
10
void UiSliderTest::sliderEvent(Ref *pSender,Slider::EventType type)
{
    if (type == Slider::EventType::ON_PERCENTAGE_CHANGED)
    {
        Slider* slider = dynamic_cast<Slider*>(pSender);
        int percent = slider->getPercent();
        _displayValueLabel->setString(String::createWithFormat("Percent %d",percent)->getCString());
    }
}

In Lua:

 
 
1
2
3
4
5
6
7
local function percentChangedEvent(sender,eventType)
        if eventType == ccui.SliderEventType.percentChanged then
            local slider = sender
            local percent = "Percent " .. slider:getPercent()
            self._displayValueLabel:setString(percent)
        end
    end  

By dynamic cast pSender to get UiSlider,then get the percentage of UiSlider to save UI resource by using squared picture.

LoadingBar

In contrast to the slider is a progress bar,one of them is controlling progress manually then return value and the other is setting value manually then update displaying. For example,when we loading some image resource the progress can show us the loading progress. Following is one usage:

In C++:

 
 
1
2
3
4
5
6
7
    LoadingBar* loadingBar = LoadingBar::create();
    loadingBar->setName("LoadingBar");
    loadingBar->loadTexture("cocosgui/sliderProgress.png");
    loadingBar->setPercent(0);

    loadingBar->setPosition(Point(widgetSize.width / 2.0f,widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
    m_pUiLayer->addChild(loadingBar);

In Lua:

 
 
1
2
3
4
5
 local loadingBar = ccui.LoadingBar:create()
    loadingBar:setTag(0)
    loadingBar:setName("LoadingBar")
    loadingBar:loadTexture("cocosui/sliderProgress.png")
    loadingBar:setPercent(0)

We did some initialize work above,if you want to get new value in real time then you need to update the value by setPercent method. When run a scene,we call the scheduleUpdate(); and implement update method ensuring it can be called every frame. Following code should be in update method:

In C++:

 
 
1
2
3
4
5
6
7
8
9
10
11
    void UILoadingBarTest_Left::update(float delta)
    {
        m_nCount++;
        if (m_nCount > 100)
        {
            m_nCount = 0;
        }

        UILoadingBar* loadingBar = dynamic_cast<UILoadingBar*>(m_pUiLayer->getWidgetByName("LoadingBar"));
        loadingBar->setPercent(m_nCount);
    }

In Lua:

 
 
1
2
3
4
5
6
7
8
9
10
11
local function update(delta)
        self._count = self._count + 1
        if self._count > 100 then
            self._count = 0
        end

        if self._uiLayer ~= nil then
            local loadingBar = self._uiLayer:getChildByTag(0)
            loadingBar:setPercent(self._count)
        end
    end

It's a increase number start from zero,you can see from left to right the length of process bar is increasing. If you want the process bar's length increasing from right from left,you can set loadingBar->setDirection(LoadingBarTypeRight); and this widget support squared picture.

TextAtlas

UILabelAtlas can display number label that jointed by images:

In C++:

 
 
1
2
3
4
 // Create the text atlas
        TextAtlas* textAtlas = TextAtlas::create("1234567890","cocosui/labelatlas.png",17,22,"0");
        textAtlas->setPosition(Vec2((widgetSize.width) / 2,widgetSize.height / 2.0f));
        _uiLayer->addChild(textAtlas); 

In Lua:

 
 
1
2
3
4
5
  local labelAtlas = ccui.TextAtlas:create()
    labelAtlas:setProperty("1234567890","0")
    labelAtlas:setPosition(cc.p((widgetSize.width) / 2,widgetSize.height / 2.0))        

    self._uiLayer:addChild(labelAtlas) 

The usage of this widget is very simple,Label is not efficient in old version so LabelAtlas is a good substitution but in version 3.0 Label has been improved a lot. Here we choose Atlas because we can custom it to get better displaying effect.

TextBMFont

In addition to UILabelAtlas,you can also display a label by UILabelBMFont.

In C++:

 
 
1
2
3
4
  // Create the TextBMFont
        TextBMFont* textBMFont = TextBMFont::create("BMFont","cocosui/bitmapFontTest2.fnt");
        textBMFont->setPosition(Vec2(widgetSize.width / 2,widgetSize.height / 2.0f + textBMFont->getContentSize().height / 8.0f));
        _uiLayer->addChild(textBMFont);

In Lua:

 
 
1
2
3
4
5
6
  local labelBMFont = ccui.TextBMFont:create()
    labelBMFont:setFntFile("cocosui/bitmapFontTest2.fnt")
    labelBMFont:setString("BMFont")
    labelBMFont:setPosition(cc.p(widgetSize.width / 2,widgetSize.height / 2.0 + labelBMFont:getContentSize().height / 8.0))        

    self._uiLayer:addChild(labelBMFont) 

Just like TextlAtlas,TextBMFont store the display information by a image,but Atlas is smaller than BMFont. You can set the parameters of the cutting,but BMFont has to be with a ".fnt" file. There are many information in it,and it also provide many display effect.

Text

Text widget can help us solve some problems such as auto wrap and so on. It's important for design a flexible UI.

In C++:

 
 
1
2
3
4
5
6
7
8
  // Create the line wrap
        Text* text = Text::create("Text can line wrap","AmericanTypewriter",32);
        text->ignoreContentAdaptWithSize(false);
        text->setContentSize(Size(280,150));
        text->setTextHorizontalAlignment(TextHAlignment::CENTER);
        text->setPosition(Vec2(widgetSize.width / 2.0f,widgetSize.height / 2.0f - text->getContentSize().height / 8.0f));
        _uiLayer->addChild(text);     

In Lua:

 
 
1
2
3
4
5
6
7
8
local textArea = ccui.Text:create()
    textArea:setTextAreaSize(cc.size(280,150))
    textArea:setTextHorizontalAlignment(cc.TEXT_ALIGNMENT_CENTER)
    textArea:setString("TextArea widget can line wrap")
    textArea:setFontName("AmericanTypewriter")
    textArea:setFontSize(32)
    textArea:setPosition(cc.p(widgetSize.width / 2,widgetSize.height / 2 - textArea:getContentSize().height / 8))  
    self._uiLayer:addChild(textArea) 

You need to kNow the size of a text area,and its alignmet(Use setTextHorizontalAlignment to set the align mode: Left,Right and Center),display content,font size and font etc.

TextField

Text Field is a very important widget,it can call device's input system to receive user's input content such as user name and password in a login scene.

In C++:

 
 
1
2
3
4
5
6
7
8
9
 // Create the textfield
        TextField* textField = TextField::create("input words here","fonts/Marker Felt.ttf",30);
        textField->ignoreContentAdaptWithSize(false);
        textField->setContentSize(Size(240,160));
        textField->setTextHorizontalAlignment(TextHAlignment::CENTER);
        textField->setTextVerticalAlignment(TextVAlignment::CENTER);
        textField->setPosition(Vec2(widgetSize.width / 2.0f,widgetSize.height / 2.0f));
        textField->addEventListener(CC_CALLBACK_2(UITextFieldTest_LineWrap::textFieldEvent,this));
        _uiLayer->addChild(textField);

In Lua:

 
 
1
2
3
4
5
6
7
8
 local textField = ccui.TextField:create()
    textField:setTouchEnabled(true)
    textField:setFontName(font_UITextFieldTest)
    textField:setFontSize(30)
    textField:setPlaceHolder("input words here")
    textField:setPosition(cc.p(widgetSize.width / 2.0,widgetSize.height / 2.0))
    textField:addEventListener(textFieldEvent) 
    self._uiLayer:addChild(textField) 

Setted properties and enabled touch,then wait user's touch event to done the text input work. setPlaceHolder can remind user to input when the widget don't show anything. Notice that the callback functions here have many statuses:

In C++:

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
   void UITextFieldTest_LineWrap::textFieldEvent(Ref *pSender,TextField::EventType type)
{
    switch (type)
    {
        case TextField::EventType::ATTACH_WITH_IME:
        {
            TextField* textField = dynamic_cast<TextField*>(pSender);
            Size widgetSize = _widget->getContentSize();
            textField->runAction(CCMoveto::create(0.225f,Vec2(widgetSize.width / 2.0f,widgetSize.height / 2.0f + textField->getContentSize().height / 2)));
            textField->setTextHorizontalAlignment(TextHAlignment::LEFT);
            textField->setTextVerticalAlignment(TextVAlignment::TOP);

            _displayValueLabel->setString(CCString::createWithFormat("attach with IME")->getCString());
        }
            break;

        case TextField::EventType::DETACH_WITH_IME:
        {
            TextField* textField = dynamic_cast<TextField*>(pSender);
            Size widgetSize = _widget->getContentSize();
            textField->runAction(CCMoveto::create(0.175f,widgetSize.height / 2.0f)));
            textField->setTextHorizontalAlignment(TextHAlignment::CENTER);
            textField->setTextVerticalAlignment(TextVAlignment::CENTER);

            _displayValueLabel->setString(CCString::createWithFormat("detach with IME")->getCString());
        }
            break;

        case TextField::EventType::INSERT_TEXT:
            _displayValueLabel->setString(CCString::createWithFormat("insert words")->getCString());
            break;

        case TextField::EventType::DELETE_BACKWARD:
            _displayValueLabel->setString(CCString::createWithFormat("delete word")->getCString());
            break;

        default:
            break;
    }
}

In Lua:

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 local function textFieldEvent(sender,eventType)
        if eventType == ccui.TextFiledEventType.attach_with_ime then
            local textField = sender
            local screenSize = cc.Director:getInstance():getWinSize()
            textField:runAction(cc.Moveto:create(0.225,cc.p(screenSize.width / 2.0,screenSize.height / 2.0 + textField:getContentSize().height / 2.0)))
            self._displayValueLabel:setString("attach with IME")
        elseif eventType == ccui.TextFiledEventType.detach_with_ime then
            local textField = sender
            local screenSize = cc.Director:getInstance():getWinSize()
            textField:runAction(cc.Moveto:create(0.175,screenSize.height / 2.0)))
            self._displayValueLabel:setString("detach with IME")
        elseif eventType == ccui.TextFiledEventType.insert_text then
            self._displayValueLabel:setString("insert words")
        elseif eventType == ccui.TextFiledEventType.delete_backward then
            self._displayValueLabel:setString("delete word")
        end
    end

First,it have four event type:

Event Type Description
TextField::EventType::ATTACH_WITH_IME Enable trigger when input
TextField::EventType::DETACH_WITH_IME Trigger when event end
TextField::EventType::INSERT_TEXT Trigger when insert text
TextField::EventType::DELETE_BACKWARD Trigger when delete text

Accroding to the event type,we can get widget's content or change widget's properties in real time. We can set widget's max text length by textField->setMaxLength(3);.

In a login scene,we usually design a user name Box and a password Box,and the widget absolutely support password Box's property:

In C++:

 
 
1
2
    textField->setPasswordEnabled(true);
    textField->setPasswordStyleText("*");

In Lua:

 
 
1
2
  textField:setPasswordEnabled(true)
  textField:setPasswordStyleTest("*")

Enable password mode first,and then set a substitute character.

uislider.png (88.3 kB) owen,2014-04-02 07:13

uitextarea.png (99.6 kB) owen,2014-04-02 07:13

uitextbutton.png (93.9 kB) owen,2014-04-02 07:13

uitextbutton9.png (96.7 kB) owen,2014-04-02 07:13

uibmfont.png (95 kB) owen,2014-04-02 07:13

uicheckbox.png (91.7 kB) owen,2014-04-02 07:13

uicheckboxs.png (90.5 kB) owen,2014-04-02 07:13

uilabelatlas.png (91.4 kB) owen,2014-04-02 07:13

uitextfield.png (85.5 kB) owen,2014-04-02 07:13

uiloadingbar.png (86.7 kB) owen,2014-04-02 07:13

cocos2dx v3 new GUI Introduction to Regular Widgets的更多相关文章

  1. ios – 在Spritekit游戏中限制GUI元素的比例

    如果我使用375×667尺寸的场景,那么一切都正确定位并具有良好的比例,但质量受损解决方法统一的GUI和游戏据我所知,处理统一GUI和游戏的最佳方法是设置场景大小,让SpriteKit从那里扩展.这是iPhone6的分数.因为SpriteKit在点上工作但设备以像素显示,对于@2x设备,场景大小将为750pxx1354px像素,对于iPhone6,场景大小将为1125pxx2031px.这如何与资产一起使用?对于Apple来说,这是一个更好的问题.显然,SpriteKit不支持纹理图集中的@3x图像.SO

  2. 如何在Xcode 4中自动生成Core Data GUI?

    我正在通过基于Xcode3编写的Mac上的LearnCocoa工作,我正在使用v4.到目前为止,我已经能够相当容易地找到解决差异的方法,但现在我正在介绍CoreData的一章,还有一部分关于能够通过Option从实体拖动到IB中的窗口来自动生成GUI,但我似乎无法在Xcode4中做到这一点.它仍然可能,或者那个能力是否与v3一起死亡?

  3. uislider – Sprite Kit iOS7 – 添加滑块

    我以为你可以在精灵套件应用程序中添加UIKit滑块/或按钮.但无法弄清楚如何做到这一点,以编程方式创建滑块的代码是以上不起作用,视图的子视图数量保持不变我假设我必须将它作为子项添加到我的图层,但addChild方法不适用于UiSlider.它需要是一个SKNode本身.我在这里的场景课中叫这个感谢评论,我可以让它显示–但我必须在viewController类中添加,就像这样在实际的场景类中是否没有它去做…

  4. swift UI专项训练31 Slider 滑块

    滑块是用一种渐进柔和的方式来展示一种设置或者一个进度。滑块的基类是UiSlider,属性比较简单主要是最小值最大值和当前值。):它最主要的事件就是值变更,跟我们之前遇到的控件差不多,现在我们让label显示滑动的当前值,最小是0,最大是10,我们上面设置过的。因为sender的值是个浮点数,所以我们要转成String,效果如下:

  5. [Swift]UIKit学习之滑块控件UISlider的用法

    UIKit学习之滑块控件UiSlider的用法Slider:Slidersenableuserstointeractivelymodifysomeadjustablevalueinanapp,suchasspeakervolumeorscreenbrightness.UiSlider:AUiSliderobjectisavisualcontrolusedtoselectasinglevaluefr

  6. swift中UISlider的使用

  7. 在Android应用程序中启用Media Volume Slider

    当按下硬件音量增大/减小按钮时,某些Android程序会触发“媒体音量”滑块.我的应用程序似乎在按下硬件按钮时设置振铃器音量.如何启用媒体音量滑块?

  8. android – 轻量级跨平台C GUI(OpenGL)

    我正在寻找一个轻量级的跨平台GUI库,用于不同的信号处理应用程序.ANSI-C程序必须与其静态链接,并且大小很重要.完成的应用程序必须在iPad,iPhone,Android,Ubuntu,Leopard,Windows等平台上具有相同的外观.Qt不合适,因为它太大了,并且在iOS设备上不起作用.我倾向于基于OpenGL的GUI库,因为每个现代目标平台都支持OpenGL,并且OpenGL应用程序在

  9. Android:用NDK构建原生GUI应用程序?

    独立于有意义的事实,如果它是一种创建Android应用程序的好方法:因为原因,我想使用NDK在C中创建带有图形用户界面的Android应用程序.到目前为止,我发现了一些关于NDK的信息,如何创建本机库以及如何从Java应用程序中访问它们.但我真正想要的是一些信息,如何创建一个视图,并从我的CNDK应用程序中添加图形用户界面元素到该视图.任何想法和提示如何做到这一点或在哪里可以找到更多的信息/HOWTOs?

  10. Android Studio“没有发现测试”

    有没有人能够在AndroidStudio中获得测试(从GUI而不是终端),我无法从GUI运行测试.每次我尝试通过GUI运行测试,我只需要得到以下消息:我可以使用以下命令从终端运行测试:我在MacOSX上运行AndroidStudio0.5.2withGradle1.11与Plugin0.9.0我的项目结构如下:我的build.gradle文件看起来类似于以下内容:如果有人有任何建议,我会非常高兴在

随机推荐

  1. 【cocos2d-x 3.x 学习笔记】对象内存管理

    Cocos2d-x的内存管理cocos2d-x中使用的是上面的引用计数来管理内存,但是又增加了一些自己的特色。cocos2d-x中通过Ref类来实现引用计数,所有需要实现内存自动回收的类都应该继承自Ref类。下面是Ref类的定义:在cocos2d-x中创建对象通常有两种方式:这两中方式的差异可以参见我另一篇博文“对象创建方式讨论”。在cocos2d-x中提倡使用第二种方式,为了避免误用第一种方式,一般将构造函数设为protected或private。参考资料:[1]cocos2d-x高级开发教程2.3节[

  2. 利用cocos2dx 3.2开发消灭星星六如何在cocos2dx中显示中文

    由于编码的不同,在cocos2dx中的Label控件中如果放入中文字,往往会出现乱码。为了方便使用,我把这个从文档中获取中文字的方法放在一个头文件里面Chinese.h这里的tex_vec是cocos2dx提供的一个保存文档内容的一个容器。这里给出ChineseWords,xml的格式再看看ChineseWord的实现Chinese.cpp就这样,以后在需要用到中文字的地方,就先include这个头文件然后调用ChineseWord函数,获取一串中文字符串。

  3. 利用cocos2dx 3.2开发消灭星星七关于星星的算法

    在前面,我们已经在GameLayer中利用随机数初始化了一个StarMatrix,如果还不知道怎么创建星星矩阵请回去看看而且我们也讲了整个游戏的触摸事件的派发了。

  4. cocos2dx3.x 新手打包APK注意事项!

    这个在编译的时候就可以发现了比较好弄这只是我遇到的,其他的以后遇到再补充吧。。。以前被这两个问题坑了好久

  5. 利用cocos2dx 3.2开发消灭星星八游戏的结束判断与数据控制

    如果你看完之前的,那么你基本已经拥有一个消灭星星游戏的雏形。开始把剩下的两两互不相连的星星消去。那么如何判断是GameOver还是进入下一关呢。。其实游戏数据贯穿整个游戏,包括星星消除的时候要加到获得分数上,消去剩下两两不相连的星星的时候的加分政策等,因此如果前面没有做这一块的,最好回去搞一搞。

  6. 利用cocos2dx 3.2开发消灭星星九为游戏添加一些特效

    needClear是一个flag,当游戏判断不能再继续后,这个flag变为true,开始消除剩下的星星clearSumTime是一个累加器ONE_CLEAR_TIME就是每颗星星消除的时间2.连击加分信息一般消除一次星星都会有连击信息和加多少分的信息。其实这些combo标签就是一张图片,也是通过控制其属性或者runAction来实现。源码ComboEffect.hComboEffect.cpp4.消除星星粒子效果消除星星时,为了实现星星爆裂散落的效果,使用了cocos2d提供的粒子特效引擎对于粒子特效不了

  7. 02 Cocos2D-x引擎win7环境搭建及创建项目

    官网有搭建的文章,直接转载记录。环境搭建:本文介绍如何搭建Cocos2d-x3.2版本的开发环境。项目创建:一、通过命令创建项目前面搭建好环境后,怎样创建自己的Cocos2d-x项目呢?先来看看Cocos2d-x3.2的目录吧这就是Cocos2d-x3.2的目录。输入cocosnew项目名–p包名–lcpp–d路径回车就创建成功了例如:成功后,找到这个项目打开proj.win32目录下的Hello.slnF5成功了。

  8. 利用cocos2dx 3.2开发消灭星星十为游戏添加音效项目源码分享

    一个游戏,声音也是非常的重要,其实cocos2dx里面的简单音效引擎的使用是非常简单的。我这里只不过是用一个类对所有的音效进行管理罢了。Audio.hAudio.cpp好了,本系列教程到此结束,第一次写教程如有不对请见谅或指教,谢谢大家。最后附上整个项目的源代码点击打开链接

  9. 03 Helloworld

    程序都有一个入口点,在C++就是main函数了,打开main.cpp,代码如下:123456789101112131415161718#include"main.h"#include"AppDelegate.h"#include"cocos2d.h"USING_NS_CC;intAPIENTRY_tWinMain{UNREFERENCED_ParaMETER;UNREFERENCED_ParaMETER;//createtheapplicationinstanceAppDelegateapp;return

  10. MenuItemImage*图标菜单创建注意事项

    学习cocos2dx,看的是cocos2d-x3.x手游开发实例详解,这本书错误一大把,本着探索求知勇于发现错误改正错误的精神,我跟着书上的例子一起调试,当学习到场景切换这个小节的时候,出了个错误,卡了我好几个小时。

返回
顶部