Time for action – creating the interface
The interface, or header file, is just a text file with the .h
extension.
- Create a new text file and save it as
HelloWorld.h
. Then, enter the following lines at the top:#ifndef __HELLOWORLD_H__ #define __HELLOWORLD_H__ #include "cocos2d.h"
- Next, add the namespace declaration:
using namespace cocos2d;
- Then, declare your class name and the name of any inherited classes:
class HelloWorld : public cocos2d::Layer {
- Next, we add the properties and methods:
protected: int _score; public: HelloWorld(); virtual ~HelloWorld(); virtual bool init(); static cocos2d::Scene* scene(); CREATE_FUNC(HelloWorld); void update(float dt); inline int addTwoIntegers (int one, int two) { return one + two; } };
- We finish by closing the
#ifndef
statement:#endif // __HELLOWORLD_H__
What just happened?
You created a header file in C++. Let's go over the important bits of information:
- In C++ you include, you do not import...