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__