Sunday, June 28, 2015

Creating a Splash scene Cocos 2d-x V3+

First off all. I'm developing games using cocos 2d-x V3.x of course cocos2d-x can be very useful because you create a game in one platform and this game will be ready for Android, Ios, Win Phone or better windows 8.1 universal apps. OK the first thing that we need is very simple we just need to create a hello world project, after that we only need is to create a new class this class will be SplashScene with the source and header file. of course this will be after the AppDelegate class that is the begging of all our code. What is the splash scene ? OK. This is my way to create a very simple splash scene, after show my amazing logo we will continue to the next scene, a hello world scene ;).

  * SplashScene.h
  * Created on: Dec 28, 2014
  *   Author: OscarLeif
 #include "cocos2d.h"
 #include "HelloWorldScene.h"
 #include "SimpleAudioEngine.h"
 using namespace CocosDenshion;
 class SplashScene: public cocos2d::Layer {
      static cocos2d::Scene* createScene();
      virtual bool init();
      void goToMainMenuScene();
      void onEnterTransitionDidFinish();
 #endif /* INTRO_SPLASHSCENE_H_ */

And that's the header file it's pretty short. Our goal to first have the splash image. Then go to the next scene. But if you want to see how works you can see my games. I always use this to create the simple splash scene. 

splash image

Another next scene.
And here I leave the code for the source file. Example of the result of this you can see my games :)

  • Through Space Game
  • Hammer Mole Game

  •  /*  
      * SplashScene.cpp  
      * Created on: Dec 28, 2014  
      *   Author: OscarLeif  
     #include "HelloWorldScene.h"  
     #include "SplashScene.h"   
     Scene* SplashScene::createScene() {  
          // 'scene' is an autorelease object  
          auto scene = Scene::create();  
          // 'layer' is an autorelease object  
          auto layer = SplashScene::create();  
          // add layer as a child to scene  
          // return the scene  
          return scene;  
     bool SplashScene::init() {  
          if (!Layer::init()) {  
               return false;  
          Size visibleSize = Director::getInstance()->getVisibleSize();  
          Vec2 origin = Director::getInstance()->getVisibleOrigin();  
          Size s = Director::getInstance()->getVisibleSize();  
          auto sprite = Sprite::create("splash.png");  
          return true;  
     void SplashScene::onEnterTransitionDidFinish() {  
          CallFunc* moveCallback= CallFunc::create(std::bind(&SplashScene::goToMainMenuScene,this));  
          DelayTime* delayAction = DelayTime::create(3.f);  
          this->runAction(Sequence::create(delayAction, moveCallback, NULL));  
     void SplashScene::goToMainMenuScene() {  
          auto helloWorldScene = HelloWorld::createScene()
          auto t = TransitionFade::create(0.8f, helloWorldScene);  

    I hope this can help you.

    No comments:

    Post a Comment