-
abhishekLikes 0Problem Description
I want to implement a scrollView in my game that should scroll horizontally. In this scrollView, I want to add button images that will launch different games.
So can you please help me with the code to setup a scrollView and add it to a scene.
I tried searching on Google, but couldnt really find a solution that clearly explains how this can be done.
Any kind of help will be appreciated.
Thanks
-
Sonar Systems adminLikes 0
Check out this link for more info http://cocos.sonarlearning.co.uk/v1.0/docs/ui-elements-such-as-uibutton
-
abhishekLikes 0
Hi Sonar Systems,
Thank you so much for your quick reply.
I did check out the abovementioned link and implemented the code for ScrollView.
But I am not getting anything on the screen at all.
Here is the code:
i added this on the top of the .cpp file:
----------------------------------------------------------------------------------------------------
#include "extensions/cocos-ext.h"
#include "ui/CocosGUI.h"
USING_NS_CC_EXT;
USING_NS_CC;
using namespace ui;
----------------------------------------------------------------------------------------------------//create menu
//--------------------------------------------------
menu = Menu::create();
menu->setPosition(Point(0, 0));
//this->addChild(menu);
bn_play = MenuItemImage::create("bn_prev.png", "bn_prev.png",CC_CALLBACK_0(SelectionScene::bn_play_tapped, this));
bn_play->setPosition(bn_play->getBoundingBox().size.width/1.5, visibleSize.height - bn_play->getBoundingBox().size.height/1.5);
menu->addChild(bn_play);
bn_more = MenuItemImage::create("bn_prev.png", "bn_prev.png",CC_CALLBACK_0(SelectionScene::bn_more_tapped, this));
bn_more->setPosition(bn_more->getBoundingBox().size.width/1.5, visibleSize.height - bn_more->getBoundingBox().size.height/1.5);
menu->addChild(bn_more);
//--------------------------------------------------
//create scrollView
//--------------------------------------------------
ui::ScrollView *scrollView = ui::ScrollView::create();
scrollView->setDirection(SCROLLVIEW_DIR_HORIZONTAL);
scrollView->setContentSize(Size(800.0, 600.0));
scrollView->setTouchEnabled(true);
scrollView->setBounceEnabled(true);
//set bg image for scrollView
scrollView->setBackGroundImage("mainMenu/bg_mainMenu.png");
//total scroll view size
scrollView->setInnerContainerSize(Size(800, 600));
scrollView->setAnchorPoint(Point(0.5, 0.5));
scrollView->addChild(menu);
scrollView->addChild(bg);
this->addChild(scrollView);
//--------------------------------------------------
so when i run the build, i simply get a black screen.
the setBackGroundImage does not show any image on screen.
am i doing something wrong?
and i am not able to use this line (because the code does not recognize Vec2)
scrollView->setAnchorPoint( Vec2( 0.5, 0.5 ) );
-
Sonar Systems adminLikes 0
how big is your main menu image?
-
abhishekLikes 0
its a bg image..
so as you said in your c++ version tutorials..
it will either be:
2272 x 1536
1136 x 768
568 x 384
so in short, its the bg image that will cover up the screen
-
Sonar Systems adminLikes 0
Do you get any errors/warnings in the console saying it couldn’t load any of the images?
-
abhishekLikes 0
can i send you a sample source code for the project?
will you be able to check that and try to figure out whats wrong?
-
Sonar Systems adminLikes 0
We are very busy so it’s not very practicle but im sure we can figure it out on here
-
abhishekLikes 0
sure..
please do try and help me out here if possible
thanks
-
Sonar Systems adminLikes 0
Try swiping on the screen to see if you can see anything coming in from the sides.
-
abhishekLikes 0
i tried swiping on the screen, but nothing happens.
and also wanted to ask you, we do have to add the scrollView to the scene like this right?
this->addChild(scrollView);
-
Sonar Systems adminLikes 0
-
abhishekLikes 0
Hi,
I already checked the abovementioned link before, but it didnt help in any way.
I am not able to implement a scrollView yet.
I know you guys are busy, but if and when you have time, can you please make a scrollView tutorial for C++ version of cocos2d-x?
You have a tutorial for the java version, so I would request you to make a video tutorial for C++ also if possible.
Thank you for your time.
:)
-
Sonar Systems adminLikes 0
Have you watched the JS version and compared as that may help.
-
barabasandras1Likes 0
Dude it won’t work if you don’t add the scrollview node to your layer..
this->addChild(scrollViewPointer);
-
abhishekLikes 1
ok i will try it out..
thanks for your suggestion..
are you into cocos2d-x as well?
i would like to connect with you as i did with sonar systems
:)
Login to reply