-
warning717Likes 1Problem Description
What code do you use in your Google Play games for changing scenes?
For example in your game “Space Jam”, the buttons for changing scenes are very smooth and responsive. However on my app, the play button which changes scenes and changes images doesnt change images. The entire app freezes for a second and then switches scenes. I have buttons which only show/hide elements on screen which are responsive and dont lag.
-
Sonar Systems adminLikes 0
Coudl you show us a video of yours.
-
warning717Likes 0
Sorry but I am unable to at the moment. I was just wondering what your setup is for changing scenes so that I could compare it to what I have
-
Sonar Systems adminLikes 0
We jsut use the default replace and push scene methods with the built in animations.
-
warning717Likes 0
Where could I find that?
-
Sonar Systems adminLikes 0
Are you using Cocos2d-x or Cocos2d-JS?
-
warning717Likes 0
Cocos2d-x
-
warning717Likes 0
Since im loading the scene with the buttons created in Cocos Studio, the code looks like this:
C++//Play Button cocos2d::ui::Button *button = ( cocos2d::ui::Button * )rootNode->getChildByTag( 8 ); button->addTouchEventListener( CC_CALLBACK_2( MainMenu::touchEventPlay, this ) );
void MainMenu::touchEventPlay( Ref *sender, cocos2d::ui::Widget::TouchEventType type ) { auto scene = LevelSelect::createScene( ); switch ( type ) { case cocos2d::ui::Widget::TouchEventType::BEGAN: break; case cocos2d::ui::Widget::TouchEventType::MOVED: break; case cocos2d::ui::Widget::TouchEventType::ENDED: Director::getInstance()->replaceScene( scene ); break; case cocos2d::ui::Widget::TouchEventType::CANCELED: break; default: break; } }
Header
void touchEventPlay( Ref *sender, cocos2d::ui::Widget::TouchEventType type );
I use this same setup to show/hide panels and changing scenes is the only time I encounter issues.
-
Sonar Systems adminLikes 0
What’s the problem with that again?
-
warning717Likes 0
Pressing the play button in the main menu which changes scenes using the code above has problems. Pressing down should change the image of the button to the button down image but instead freezes the app until you release the button which pauses for a second and then changes scenes. I have other buttons with the same code but for the action instead of changing scenes it shows/hides a panel. Those buttons behave correctly and change images when pressed/released and dont lag/freeze the app. I was looking for the exact button code/setup used in one of your successful apps such as Space Jam
-
Sonar Systems adminLikes 0
Where on your game are you displaying this button?
-
warning717Likes 0
MainMenu screen, this is the second screen right after the splashscreen. It isn’t in any containers and the button was made in Cocos Studio
-
Sonar Systems adminLikes 0
Has this seen been pushed on aka is there another scene underneath on the stack?
-
warning717Likes 0
I think so. Are you asking if the main menu scene loads another scene because it does. This play button which isnt working correctly loads up another scene. Im using replace scene to load the scene on button press
-
Sonar Systems adminLikes 0
But I mean the scene this button is on, is it on a scene that has been pushed or replaced onto the stack?
-
warning717Likes 0
replaced
-
Sonar Systems adminLikes 0
OK
Could you list the entire flow of the game aka what scene goes to what and whether it’s pushed, popped or replaced onto the stack. This will help us better understand the game to assist you.
-
warning717Likes 0
SplashScreen → replace scene with transition fade → MainMenuScene
MainMenuScene → replace scene → LevelSelectScene
LevelSelectScene → replace scene → Level1Scene
-
warning717Likes 0
Is replacing the scenes a mistake? How do you use popping/pushing scenes and what are the pros/cons of using that over replacing.
-
Sonar Systems adminLikes 0
Replacing is the best for this, what part of your code in each seen actually calls the replace code aka what is the flow within each scene.
-
warning717Likes 0
cocos2d::ui::Button *button = ( cocos2d::ui::Button * )rootNode->getChildByTag( 8 ); button->addTouchEventListener( CC_CALLBACK_2( MainMenu::touchEventPlay, this ) ); void MainMenu::touchEventPlay( Ref *sender, cocos2d::ui::Widget::TouchEventType type ) { auto scene = LevelSelect::createScene( ); switch ( type ) { case cocos2d::ui::Widget::TouchEventType::BEGAN: break; case cocos2d::ui::Widget::TouchEventType::MOVED: break; case cocos2d::ui::Widget::TouchEventType::ENDED: Director::getInstance()->replaceScene( scene ); break; case cocos2d::ui::Widget::TouchEventType::CANCELED: break; default: break; } }
The replace code is in the void part
-
Sonar Systems adminLikes 0
Honestly I can’t see anything wrong, I have used similar code.
Try a fresh project.
-
warning717Likes 1
Oh okay well thanks for your help anyways :)
Login to reply