前提准备 添加触摸条件
头文件声明
CCSprite *_sprite;
int flag;//定义图片变量
virtual void registerWithTouchDispatcher(void);
virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
//.cpp
初始化中:
this->setTouchEnabled(true);
并且加入贴图集(代码略。。。)
添加精灵
flag = 1;
bool PhotoScene::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
return true;
}
void PhotoScene::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
{
flag +=1;
if (flag>3) {
flag = 1;
}
if (flag==1) {
CCSpriteFrame *frame=CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("s1");
_s->setDisplayFrame(frame);
}
else if (flag==2) {
CCSpriteFrame *frame=CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("s2");
_s->setDisplayFrame(frame);
}
else if (flag==3) {
CCSpriteFrame *frame=CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("s3");
_s->setDisplayFrame(frame);
}