练手的小程序,cocos2dx的c++编写,在界面上绘制一个一直运动的小球,其在遇到边界时反弹。
头文件
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
class HelloWorld : public cocos2d::Layer
{
public:
// there's no 'id' in cpp, so we recommend returning the class instance pointer
static cocos2d::Scene* createScene();
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
// implement the "static create()" method manually
CREATE_FUNC(HelloWorld);
private:
float widthLeft,widthRight,heightUp,heightDown;
cocos2d::DrawNode* ball;
int speedX,speedY;
};
#endif // __HELLOWORLD_SCENE_H__
源文件
#