Cocos2dx项目启程一 之 封装属于我的精灵类
2013-09-03 16:59
218 查看
给自己的假期就快要结束了,该要做点事情了,哪怕简单的不好的也比不做的有意义。
/*#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
相关文章推荐
- Cocos2dx项目启程一 之 封装属于我的精灵类
- Cocos2dx项目启程二 之 封装属于我的按钮类
- Cocos2dx项目启程二 之 封装属于我的按钮类
- Cocos2dx项目启程三 之 架构项目之切换场景
- 使用dr.memory在win32环境下调试 cocos2dx 项目的内存异常
- cocos2dx在命令行下创建项目
- QiYuAdmin-Thymeleaf的include封装共用js和css(项目优化)
- Cocos2dx 学习笔记整理----在项目中使用图片(三)
- cocos2dx 2.2.1创建项目
- 共享两个做项目最常用功能操作的封装类
- [js项目]封装库-下拉菜单
- 项目中使用的ConfigUtil 类的封装,支持多元
- eclipse开发cocos2dx 3.2环境搭建之三: ccp-tests项目编译 (this project is not a CDT project)
- 【iOS-cocos2d-X 游戏开发之四】Cocos2dX创建Android NDK新项目并编译导入Eclipse中正常运行!
- 运用Python运行cocos2dx-lua/js项目
- 项目结尾公共模块WebService封装
- Cocos2d-x游戏开发之整合cocos2dx的Android项目到Xcode项目中
- Cocos2dx项目--动作类游戏内存优化--Spine结构分析1
- cocos2dx在vs2013加载项目失败(针对路径更改问题)
- swift项目第六天:中间发布按钮的封装以及监听点击事件