Using ScrollView

Every few months I try and get user interface components working in a project I’m doing (buttons, scrollview, etc) and the result is complete failure. I come to these forums, ask for help, no one answers and I abandon it and just use my own classes.

I am now trying to get ScrollView working.

Please, can anyone give the EXACT steps needed to use either extensions or ui components in a c++ application in Windows? All platforms really, but for now I just want to prototype on the desktop.

I’ve read through every example online with outdated and useless information but the bottom line is it always fails with

unresolved external symbol

I’ve added “$(EngineRoot);” as an additional include dependency as suggested but still no go.

All of the documentation available gives examples of usage, but absolutely no indication as to how to actually add it to your project to compile.

What I’ve tried (summarized):

include "cocos-ext.h" and using namespace extension;
auto scrollView = ScrollView::create();

Fails.

Also tried:

include "ui\CocosGUI.h" and using namespace ui;
auto scrollView = ScrollView::create();

Fails

Am I stupid? Why can’t I get this working?

Using Visual Studio 2013 with Cocos2d-x 3.2

Thanks…

Can you please be more explicit with your error messages? Maybe copy and paste the error messages? For example, what does the “unresolved external symbol” error message say in full?

Using Cocos2d-x 3.0 with XCode on OSX, I tried including the cocos-ext.h header and used USING_NS_EXT, and added a scroll view using auto scrollView = ScrollView::create(); and it worked fine for me; no errors at all. I believe that is how it should be used.

I recommend the ScrollView in ui:: over the one in extensions::.
All you should have to do is #include "ui/CocosGUI.h" and access it through cocos2d::ui::ScrollView. Looks like you’re doing that. Granted I’m on OS X, and v3.3rc0.

Try giving use the the exact error output for more assistance.

Thanks to you both for responding.

So doing this from scratch again, if I just include

"cocos-ext.h"

and do:

auto scrollView = extension::ScrollView::create();

I get the following error:

\cocos2d\extensions\gui\ccscrollview\ccscrollview.h(32): fatal error C1083: Cannot open include file: 'extensions/ExtensionMacros.h': No such file or directory

Which after googling I found out I needed to add

$(EngineRoot);

to the additional include directories. Note that there is nothing documented about this, just forum members asking the same questions like I am.

Then when I build I get

error LN"2019: unresolved external symbol "public: static class cocos2d::extension::ScrollView * __cdecl cocos2d::extension::ScrollView::create(void)" (?create@ScrollView@extension@cocos2d@@SAPAV123@XZ) referenced in function "public: virtual bool __thiscall GameScene::init(void)" (?init@GameScene@@UAE_NXZ)

And that’s where I’m stuck.

On Android I had to change it to #include "extensions/cocos-ext.h". I don’t know how that would affect ios.

Uncommented

LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static

and

$(call import-module,extensions)

in the Android.mk

Then it builds fine for Android.

I’ll try ui:: again and report back but I believe I will have the same issue. Both of you are on OSX, so maybe this is an additional, undocumented, step to preform. Just like adding the additional dependency.

Ok, I just tried changing to:

#include "ui/CocosGUI.h"

and

auto scrollView = ui::ScrollView::create();

Same thing:

error LNK2019: unresolved external symbol "public: static class cocos2d::ui::ScrollView * __cdecl cocos2d::ui::ScrollView::create(void)" (?create@ScrollView@ui@cocos2d@@SAPAV123@XZ) referenced in function "public: virtual bool __thiscall GameScene::init(void)" (?init@GameScene@@UAE_NXZ)

I believe “unresolved external symbol” usually means you have the header for a class in your project, but not the source file to go with it.

Anyway, I downloaded Cocos2d-x 3.2 to my Windows PC and opened it in Visual Studio 2013, to match what you are using. I tried your code and got the exact same error as you did, so this is definitely not something you have done wrong. Well, not something you’ve screwed up. As I discovered, you have just not added the necessary bits to the project, which is Cocos2d’s fault, unless it was designed this way.

Anyway, here is how I fixed it:

  1. Right-click on your solution, e.g. “Solution ‘MyGame’ (X projects)” at the top of the Solution Explorer, and choose Add->Existing Project…
  2. Navigate to cocos->ui->proj.win32 and select libGUI.vcxproj. (This project has the source for the ScrollView.)
  3. Do the same thing again, but navigate to extensions->proj.win32 and add libExtensions.vcxproj. (This has the code Scale9Sprite, I believe, which ScrollView seems to depend on.)
  4. Right-click on your main project, e.g. MyGame (the project in Solution Viewer that has bold text), and choose Properties.
  5. Click on Common Properties at the top of the left-side area. The click “Add New Reference…” and click the checkbox beside libExtensions and libGUI.

Your project should hopefully now build without error.

@grimfate, you nailed it. I can compile without issue now. Thank You So Much!

Those changes alone work for ui::. For extension:: I had to also include $(EngineRoot); in the additional include directory.

It’s such a relief to know I wasn’t going crazy. I guess I just expected everything to work “out of the box” since there wasn’t anything documented about special setup requirements in Windows.

Thanks again, now to dive in and start learning how to use these controls.