Time for action – creating the implementation
The implementation is a text file with the .cpp
extension:
- Create a new text file and save it as
HelloWorld.cpp
. At the top, let's start by including our header file:#include "HelloWorld.h"
- Next, we implement our constructor and destructor:
HelloWorld::HelloWorld () { //constructor } HelloWorld::~HelloWorld () { //destructor }
- Then comes our static method:
Scene* HelloWorld::scene() { auto scene = Scene::create(); auto layer = HelloWorld::create(); scene->addChild(layer); return scene; }
- And then come our two remaining public methods:
bool HelloWorld::init() { // call to super if ( !Layer::init() ) { return false; } //create main loop this->scheduleUpdate(); return true; } void HelloWorld::update (float dt) { //the main loop }
What just happened?
We created the implementation for our HelloWorld
class. Here are the most important bits to take...