cocos2dx之如何实现自己的sprite
来源:互联网 发布:大数据培训课程哪家好 编辑:程序博客网 时间:2024/05/19 05:40
可能在制作游戏的过程中,用到sprite,但是它本省的方法有限,我需要再次扩充它,那么我们可以通过继承得到自定义的sprite:
定义如下:
#ifndef MYSPRITEBASE_H_#define MYSPRITEBASE_H_#include "cocos2d.h"USING_NS_CC;class MySprite : public CCSprite, public CCStandardTouchDelegate{public: MySprite(); ~MySprite();public: CCRect rect(); bool initWithTexture(CCTexture2D* aTexture); void onEnter(); void onExit(); bool containsTouchLocation(CCTouch* touch); void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent); void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent); void ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent); CCObject* copyWithZone(CCZone *pZone); void touchDelegateRetain(); void touchDelegateRelease(); static MySprite *paddleWithTexture(CCTexture2D* aTexture); static MySprite *create(CCTexture2D *pTexture);}; // end of MySprite#endif //MYSPRITEBASE_H_
在这里我们采用的消息类是用到的:CCStandardTouchDelegate类。
当然也可以用:CCTargetedTouchDelegate
具体实现:
#include "MySpriteBase.h"MySprite::MySprite() { CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this, 0);}MySprite::~MySprite() {}CCRect MySprite::rect() { CCSize s = getTexture()->getContentSize(); return CCRectMake(s.width / 2, -s.height / 2, s.width, s.height);}bool MySprite::initWithTexture(CCTexture2D* aTexture) { if( CCSprite::initWithTexture(aTexture) ) { return true; } return false;}MySprite *MySprite::create(CCTexture2D *pTexture) { MySprite *pobSprite = new MySprite(); if (pobSprite && pobSprite->initWithTexture(pTexture)) { pobSprite->autorelease(); return pobSprite; } CC_SAFE_DELETE(pobSprite);}void MySprite::onEnter() { CCSprite::onEnter();}void MySprite::onExit() { CCSprite::onExit();}bool MySprite::containsTouchLocation(CCTouch* touch) { return true;}void MySprite::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) {}void MySprite::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent) {}void MySprite::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent) {}CCObject* MySprite::copyWithZone(CCZone *pZone) { this->retain(); return this;}void MySprite::touchDelegateRetain() { this->retain();}void MySprite::touchDelegateRelease() { this->release();}MySprite* paddleWithTexture(CCTexture2D* aTexture) { MySprite* pPaddle = new MySprite(); pPaddle->initWithTexture( aTexture ); pPaddle->autorelease(); return pPaddle;}
- cocos2dx之如何实现自己的sprite
- 【cocos2dx】如何创建自己定义的精灵类Sprite
- cocos2dx之创建有渐影效果的sprite
- cocos2dx之创建有渐影效果的sprite
- cocos2dx--sprite的理解
- cocos2dx-sprite的用法
- 《转》cocos2dx 如何取一个sprite的颜色值
- cocos2dx-3.0 之sprite学习:
- cocos2dx sprite的draw函数
- cocos2dx Texture、SpriteFrame、Sprite的区别
- cocos2dx显示sprite的矩形框
- cocos2dx Texture、SpriteFrame、Sprite的区别
- 在cocos2dx 3.x 中实现带颜色滤镜的Sprite
- 在cocos2dx 3.x 中实现带颜色滤镜的Sprite
- css sprite的实现
- 15、Cocos2dx 3.0游戏开发找小三之Sprite:每个精灵都是上辈子折翼的天使
- cocos2dx-3.0以上版本之 创建Sprite精灵的6种形式
- cocos2dx中使用tiled地图实现sprite动态遮挡
- UBIFS文件系统简介 与 利用mkfs.ubifs和ubinize两个工具制作UBI镜像
- onMeasure实例分析
- C#与非托管win32函数互操作方法
- Memory驱动——测试程序
- PhoneGap 学习资料汇总
- cocos2dx之如何实现自己的sprite
- Edmonds Karp 算法
- 数据结构比看---排序算法总结
- 用Gearman做队列来实现消息推送
- ocr样本训练
- Kruskal求两点之间边权值最小的边+Uva10048
- 数组排序(冒泡法 b)
- Cacti命令行添加监控详解(转)
- 转储控制文件