cocos2d-x学习笔记(9)--effect(特效)
cocos2d-x学习笔记(9)--effect(特效)
在游戏中,我们经常会看到一些打斗场面使整个屏幕产生波浪效果,或者在切换场景是出现翻页效果等等。下面,我会把所有的特效全部罗列出来,一共有22种,比较多。其实每一个类就是一个特效类,我们只要掌握特效的是用方法,那么久可以掌握全部特效的是用。
step1:创建cocos2d-win32 application,并命名为effecttest
step2:在HelloWorldScene.h中添加如下的类,
其中第一个类是最重要的:
[cpp]
class EffectLayer:public CCLayerColor//CCLayerColor可以设置背景颜色
{
protected:
CCSprite* m_player ;
public:
EffectLayer();
~EffectLayer();
virtual void onEnter();
virtual std::string title();
void backCallback(CCObject* pSender);
void restartCallback(CCObject* pSender);
void nextCallback(CCObject* pSender);
};
[cpp]
//以下的类都是特效类
class Shaky3DDemo:public CCShaky3D
{
public:
static CCActionInterval* actionWithDuration(ccTime d)
{
return CCShaky3D::actionWithRange(5, true, ccg(15, 10), d);
}
};
class Waves3DDemo : public CCWaves3D
{
public:
static CCActionInterval* actionWithDuration(ccTime t)
{
return CCWaves3D::actionWithWaves(5, 40, ccg(15,10), t);
}
};
class FlipX3DDemo : public CCFlipX3D
{
public:
static CCActionInterval* actionWithDuration(ccTime t)
{
CCFlipX3D* flipx = CCFlipX3D::actionWithDuration(t);
CCActionInterval* flipx_back = flipx->reverse();
CCDelayTime* delay = CCDelayTime::actionWithDuration(2);
return (CCActionInterval*)(CCSequence::actions(flipx, delay, flipx_back, NULL));
}
};
class FlipY3DDemo : public CCFlipY3D
{
public:
static CCActionInterval* actionWithDuration(ccTime t)
{
CCFlipY3D* flipy = CCFlipY3D::actionWithDuration(t);
CCActionInterval* flipy_back = flipy->reverse();
CCDelayTime* delay = CCDelayTime::actionWithDuration(2);
return (CCActionInterval*)(CCSequence::actions(flipy, delay, flipy_back, NULL));
}
};
class Lens3DDemo : public CCLens3D
{
public:
static CCActionInterval* actionWithDuration(ccTime t)
{
CCSize size = CCDirector::sharedDirector()->getWinSize();
return CCLens3D::actionWithPosition(CCPointMake(size.width/2,size.height/2), 240, ccg(15,10), t);
}
};
class Ripple3DDemo : public CCRipple3D
{
public:
static CCActionInterval* actionWithDuration(ccTime t)
{
CCSize size = CCDirector::sharedDirector()->getWinSize();
return CCRipple3D::actionWithPosition(CCPointMake(size.width/2,size.height/2), 240, 4, 160, ccg(32,24), t);
}
};
class LiquidDemo : public CCLiquid
{
public:
static CCActionInterval* actionWithDuration(ccTime t)
{
return CCLiquid::actionWithWaves(4, 20, ccg(16,12), t);
}
};
class WavesDemo : public CCWaves
{
public:
static CCActionInterval* actionWithDuration(ccTime t)
{
return CCWaves::actionWithWaves(4, 20, true, true, ccg(16,12), t);
}
};
class TwirlDemo : public CCTwirl
{
public:
static CCActionInterval* actionWithDuration(ccTime t)
{
CCSize size = CCDirector::sharedDirector()->getWinSize();
return CCTwirl::actionWithPosition(CCPointMake(size.width/2, size.height/2), 1, 2.5f, ccg(12,8), t);
}
};
class ShakyTiles3DDemo : public CCShakyTiles3D
{
public:
static CCActionInterval* actionWithDuration(ccTime t)
{
return CCShakyTiles3D::actionWithRange(5, true, ccg(16,12), t) ;
}
};
class ShatteredTiles3DDemo : public CCShatteredTiles3D
{
public:
static CCActionInterval* actionWithDuration(ccTime t)
{
return CCShatteredTiles3D::actionWithRange(5, true, ccg(16,12), t);
}
};
class ShuffleTilesDemo : public CCShuffleTiles
{
public:
static CCActionInterval* actionWithDuration(ccTime t)
{
CCShuffleTiles* shuffle = CCShuffleTiles::actionWithSeed(25, ccg(16,12), t);
CCActionInterval* shuffle_back = shuffle->reverse();
CCDelayTime* delay = CCDelayTime::actionWithDuration(2);
return (CCActionInterval*)(CCSequence::actions(shuffle, delay, shuffle_back, NULL));
}
};
class FadeOutTRTilesDemo : public CCFadeOutTRTiles
{
public:
static CCActionInterval* actionWithDuration(ccTime t)
{
CCFadeOutTRTiles* fadeout = CCFadeOutTRTiles::actionWithSize(ccg(16,12), t);
CCAct
补充:移动开发 , 其他 ,