Cocos2dx项目启程一 之 封装属于我的精灵类

给自己的假期就快要结束了,该要做点事情了,哪怕简单的不好的也比不做的有意义。
/*#pragma once 保证头文件只被编译一次
#pragma once是编译器相关的,就是说即使这个编译系统上有效,
但在其他编译系统也不一定可以,不过现在基本上已经是每个编译器都有这个杂注了。

#ifndef,#define,#endif是C/C++语言中的宏定义,通过宏定义避免文件多次编译。
所以在所有支持C++语言的编译器上都是有效的,如果写的程序要跨平台,最好使用这种方式。*/
#ifndef MY_SPRITE_H
#define MY_SPRITE_H

#include "common.h"

//等量切割帧-精灵类
class CMySprite
{
	//资源名字
	std::string		m_pszResourceName;	
	//图片资源
	cocos2d::CCSprite*	m_pccsprite;			
	//当前帧
	unsigned char		m_byCurrentFrame;	
	//总帧数
	unsigned char		m_byFrames;			
	//当前列
	unsigned char		m_byCurCol;			
	//当前行
	unsigned char		m_byCurRow;			
	//帧总列
	unsigned char		m_byCol;			
	//帧总行
	unsigned char		m_byRow;			
	//帧宽
	unsigned int		m_uiframeWidth;		
	//帧高
	unsigned int		m_uiframeHeight;	

public:
	CMySprite(void);
	~CMySprite(void);

	//资源接口
public:
	//载入资源
	bool LoadImage(const char* pszResourceName,unsigned char col = 1,unsigned char row = 1);

	bool createWithSpriteFrameName(const char* pszResourceName);
	//获取资源数据
	cocos2d::CCSprite* GetRenderData();

	//资源是空判断
	bool IsNull();

	//销毁资源
	void DestroyImage();

	//功能接口
public:
	//切换下帧
	void NextFrame();
	//设置帧
	void SetFrame(unsigned char byFrame);
	//获取当前帧
	unsigned char GetFrame();
	//获取当前所有帧数
	unsigned char GetFrames();
	//切换至Row行
	void SetCurRow(unsigned char Row);
	//获取当前行
	unsigned char GetCurRow();
	//切换至col列
	void SetCurCol(unsigned char col);
	//获取当前列
	unsigned char GetCurCol();
	//获取单帧宽
	unsigned int GetFrameWidth();
	//获取单帧高
	unsigned int GetFrameHeight();
	//设置坐标
	void SetPosition(float x,float y);
	//获取坐标
	cocos2d::CCPoint GetPosition();
	//获取X坐标
	float GetX();
	//获取Y坐标
	float GetY();
	//设置矩形
	void SetBox(CCRect crt);
	//获取矩形
	CCRect GetBox();

private:
	//设置切割矩形
	void ResetTextureRect();

};

#endif


原文地址:https://www.cnblogs.com/riskyer/p/3299572.html