Head
#ifndef __test_h__
#define __test_h__
#include "Cocos2d.h"
USING_NS_CC;
Class Test:public Layer
{
Public://Do not forget the public or the default is that private is not normal execution
Static Scene * Createscene ();
virtual BOOL init ();
Create_func (Test);
};
#endif//__test_h__
source file
#include "Test.h"
USING_NS_CC;
Scene * Test::createscene ()
{
Auto scene = Scene::create ();
Auto layer = Test::create ();
Scene->addchild (layer);
return scene;
}
BOOL Test::init ()
{
if (! Layer::init ())
{
return false;
}
Size visiblesize = director::getinstance ()->getvisiblesize ();
VEC2 origin = Director::getinstance ()->getvisibleorigin ();
Auto label = Labelttf::create ("Hello World", "Arial", 24);
Label->setposition (VEC2 (origin.x + visiblesize.width/2,origin.y + visiblesize.height-label->getContentSize () . height));
This->addchild (label, 1);
return true;
}
And then in the AppDelegate.cpp. Add header File
#include "AppDelegate.h"
#include "HelloWorldScene.h"
#include "Test.h"//Add header file
USING_NS_CC;
Appdelegate::appdelegate () {
}
Appdelegate::~appdelegate ()
{
}
BOOL Appdelegate::applicationdidfinishlaunching () {
Initialize Director
Auto director = Director::getinstance ();
Auto Glview = Director->getopenglview ();
if (!glview) {
Glview = Glview::create ("My Game");
Director->setopenglview (Glview);
}
Turn on display FPS
Director->setdisplaystats (TRUE);
Set FPS. The default value is 1.0/60 if you don ' t call this
Director->setanimationinterval (1.0/60);
Create a scene. It ' s an Autorelease object
Auto scene = Helloworld::createscene ();
Auto scene = Test::createscene (); Instantiating a scene
Run
director->runwithscene (scene);//Add the instantiated scene name to it.
return true;
}
This function was called when the app was inactive. When comes a phone call,it ' s be invoked too
void Appdelegate::applicationdidenterbackground () {
Director::getinstance ()->stopanimation ();
If you use Simpleaudioengine, it must is pause
Simpleaudioengine::getinstance ()->pausebackgroundmusic ();
}
This function would be called when the app is active again
void Appdelegate::applicationwillenterforeground () {
Director::getinstance ()->startanimation ();
If you use Simpleaudioengine, it must resume here
Simpleaudioengine::getinstance ()->resumebackgroundmusic ();
}
Cocos2d-x 3.0 Create a scene and set the scene when the project starts to execute on the active