Cocos2dx v3.0 UI Classes - gotta get this workign

Cocos Version: 3.0 (latest)
Issue: Trying to get UI classes to work. Perhaps I need CocosStudio installed?

My code contains the following:

#include "CocosGUI.h"

//auto uLayer = UILayer::create();
	//uLayer->addWidget(uLabel);
	//addChild(uLayer);

	//auto uButton = UIButton::create();
	//uButton->setTouchEnabled(true);
	//uButton->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
	//uButton->setPosition(Point(size.width / 2, size.height / 2) + Point(0, -50));
	//uButton->addTouchEventListener(this,toucheventselector(HelloWorld::touchEvent));
	//uLayer->addWidget(uButton);

	//auto uLabel = UILabel::create();
	//uLabel->setText("Hello Cocos!");
	//uLabel->setFontName("Marker Felt");
	//uLabel->setFontSize(30);
	//uLabel->setColor(Color3B(159, 168, 176));
	//uLabel->setPosition(Point(size.width / 2, size.height / 2));

Errors I get:

Error	1	error C1083: Cannot open include file: 'cocostudio/ObjectFactory.h': No such file or directory	..\cocos\ui\guidefine.h
Error	2	IntelliSense: cannot open source file "cocostudio/ObjectFactory.h"	..\cocos\ui\GUIDefine.h

you need to add cocostudio directory into your project so that it can search its header file. Its in ROOT\cocos\editor-support\ then you can see cocostudio there. Once it is done, you might have LINKER error, you need to link to cocostudio library as well.

Please see attached includes.png

I have added (as highlighted in yellow) what I think is the includes for cocos ui and cocos studio and even added both ui and studio projects as libraries.

I still get the errors above, and all my efforts result in the same errors.

It shouldn’t be this hard :frowning:

Don’t use $() Use %()

I now get the following linker errors (see linker_err.png). Anyone able to help?

Do I use a ‘using’ or put something into the linker directories?

I got it to work using as reference the sample tests setup.
Then, I added references to libCocosStudio (don’t know if it still necessary) and libGUI. It worked perfectly.
Also, UILayer is not necessary anymore. I just added directly in my Scene my UI components.
Hope it helps. I searched a lot about this issue. :wink:

I meet the same issue as @utilae reported.
I have added the libGUI and libCocosStudio project in Visual Studio. The game project also include the project reference and dependency/build order has been setup.

Haven’t meet the same issue before v3.

Sadly… by solving it late at night and later deleting the folder with the test working :frowning: I’m trying to reproduce my sucess again WITH NOTES.
If I get it working, I’ll post again

Got it!
New GUI in wp8 projects:

  1. Add existing libGUI project:
MyCompany\MyGame\cocos2d\cocos\ui\proj.wp8
2. Add New Reference in HelloCppComponent project (see image) 3. Include #include "ui/CocosGUI.h" 4. Using IMPORTANT: always after USING_NS_CC USING_NS_CC // must come befor using namespace ui using namespace ui; 5. Test code: // TEST WITH NEW LABEL auto size = Director::getInstance()->getWinSize();

auto label = Label::create(L"Olá Cocos", “CALIBRI”, 30);
label->setColor(Color3B(159, 168, 176));
label->setPosition(Point(size.width / 2, size.height / 2));

this->addChild(label);

In order to add a simple Button, besides libGUI, I also had to add and reference:

  • libCocosStudio
  • libExtensions

I’m getting the same error… what do you mean by “add cocostudio directory into your project”? In Visual Express 2013, I’ve tried adding that directory into the Include paths (Project/Properties), and still doesn’t work. The library “libCocosStudio” is also referenced (but that’s not related to the compiler won’t finding the headers, of course)

My notes on this subject. Hope this helps.

Add existing projects

Solution Explorer -> Right Click Solution ‘YourProjectName’ -> Add -> Existing Project:

Cocos2d
…YourProjectName\cocos2d\cocos\2d\cocos2d.vcxproj

Extensions
…YourProjectName\cocos2d\extensions\proj.win32\libExtensions.vcxproj

GUI
…YourProjectName\cocos2d\cocos\ui\proj.win32\libGUI.vcxproj

Solution Explorer -> Right Click Solution ‘YourProjectName’ -> Properties
-> Common Properties -> Project Dependencies:

Tick all the dependencies under ‘Depends on’.

Build project.

Linker

Solution Explorer -> Right Click Project -> Properties
-> Configuration Properties -> Linker -> Input

Add file references into [Additional Dependencies]

Examples:

libExtensions.lib;libCocosStudio.lib;libGUI.lib;libcocos2d.lib;libchipmunk.lib;libAudio.lib;

Libraries

A library file (.lib) can be created by dragging a project/solution file eg libGUI.vcxproj
into the Solution Explorer to add it to the project.  It will become eg libGUI

Solution Explorer -> Right Click Project -> Build Dependencies
to make sure the newly added project is ticked so it is built.

Build the project and the .lib file will be created in the project debug directory.

The .lib references must be added into the Linker Additional Dependencies eg libGUI.lib;

The project that was added in eg libGUI, can be removed.

1 Like

Here is some working code for the uiButton.

Cocos2dx v3.x c++ new ui button solved

Solution was as follows:

  1. Download Cocos2dx v3.1.1 and setup Project to use updated SDK.

  2. Code changes:

auto uButton = ui::Button::create();
        uButton->setTouchEnabled(true);
        uButton->loadTextures(“ButtonNormal.png”, “ButtonSelected1.png”, “”);
        uButton->setPosition(Point(visibleSize.width / 2, visibleSize.height / 2) + Point(0, -50));
        uButton->addTouchEventListener(CC_CALLBACK_2(MenuScene::TouchEnd, this));
        addChild(uButton);

void MenuScene::TouchEnd(Ref* pSender, ui::Widget::TouchEventType eEventType)
    {
    
        if (eEventType != ui::Widget::TouchEventType::ENDED) return;
    
    #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
        MessageBox(“You pressed the close button. Windows Store Apps do not implement a close button.”, “Alert”);
        return;
    #endif
    
        Director::getInstance()->end();
    
    #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        exit(0);
    #endif
    }

Thanks a lot for your response, @utilae. Unfortunately, even after following your notes, I still get the same output: error C1083: Cannot open include file: ‘cocostudio/ObjectFactory.h’: No such file or directory

This is clearly a compile error, not a linking one… but I’m unable to tell Visual Studio where to look for the include headers, it seems…

I’ll try upgrading the project to v3.2 rc0, and update here…

Make sure you have the following:

#include "ui/CocosGUI.h"

USING_NS_CC;

And that you include the ui:: eg

auto uButton = ui::Button::create();

Thanks, I had already checked that, I had CocosGUI.h included. The only way to make it work, was to copy the cocostudio folder into my project. Still, I got other issues later… and never got the VideoPlayer component to work.

I’m feeling that the v3.X branch is still very unstable, so I’ve decided to downgrade my project to cocos2d-x v2.2.5. I love the new API, but I prefer to work with more solid ground :stuck_out_tongue: