程序运行截图
需求分析
第一
实现一个用来刷帧的线程
第二
实现用来绘制游戏画面的函数
需要能够绘制一幅图片的指定区域
具体做法是
新建一个CCSprite对象,然后为其指定图片并且使用SetTextureRect函数指定特定区域。
第三
对用户的指令做出响应
这里用到的方法是在屏幕上显示上下左右让用户选择。
代码实现
HelloWorldScene.h
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
#include "SimpleAudioEngine.h"
USING_NS_CC;
class Sprite
{
public:
Sprite(int x,int y,int sw,int sh,int direction,int status,int speed,CCSprite* sprite);
int x;
int y;
int w;
int h;
int direction;
int status;
int speed;
CCSprite*sprite;
};
class HelloWorld : public cocos2d::CCLayer
{
public:
vir