mirror of https://github.com/axmolengine/axmol.git
fixed #1114: Updated SchedulerTest and ShaderTest. Used CCControlSlider instead of UISlider. Added some resources.
This commit is contained in:
parent
c501255a7a
commit
e673bfae90
|
@ -45,9 +45,9 @@ bool CCActionTween::initWithDuration(ccTime aDuration, const char* key, float fr
|
||||||
{
|
{
|
||||||
if (CCActionInterval::initWithDuration(aDuration))
|
if (CCActionInterval::initWithDuration(aDuration))
|
||||||
{
|
{
|
||||||
key_ = key;
|
m_strKey = key;
|
||||||
to_ = to;
|
m_fTo = to;
|
||||||
from_ = from;
|
m_fFrom = from;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,17 +58,17 @@ void CCActionTween::startWithTarget(CCNode *pTarget)
|
||||||
{
|
{
|
||||||
CCAssert(dynamic_cast<CCActionTweenDelegate*>(pTarget), "target must implement CCActionTweenDelegate");
|
CCAssert(dynamic_cast<CCActionTweenDelegate*>(pTarget), "target must implement CCActionTweenDelegate");
|
||||||
CCActionInterval::startWithTarget(pTarget);
|
CCActionInterval::startWithTarget(pTarget);
|
||||||
delta_ = to_ - from_;
|
m_fDelta = m_fTo - m_fFrom;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCActionTween::update(ccTime dt)
|
void CCActionTween::update(ccTime dt)
|
||||||
{
|
{
|
||||||
dynamic_cast<CCActionTweenDelegate*>(m_pTarget)->updateTweenAction(to_ - delta_ * (1 - dt), key_.c_str());
|
dynamic_cast<CCActionTweenDelegate*>(m_pTarget)->updateTweenAction(m_fTo - m_fDelta * (1 - dt), m_strKey.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
CCActionInterval* CCActionTween::reverse()
|
CCActionInterval* CCActionTween::reverse()
|
||||||
{
|
{
|
||||||
return CCActionTween::actionWithDuration(m_fDuration, key_.c_str(), to_, from_);
|
return CCActionTween::actionWithDuration(m_fDuration, m_strKey.c_str(), m_fTo, m_fFrom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,6 @@ class CC_DLL CCActionManager : public CCObject
|
||||||
public:
|
public:
|
||||||
CCActionManager(void);
|
CCActionManager(void);
|
||||||
~CCActionManager(void);
|
~CCActionManager(void);
|
||||||
bool init(void);
|
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
|
|
||||||
|
|
|
@ -67,9 +67,9 @@ public:
|
||||||
void update(ccTime dt);
|
void update(ccTime dt);
|
||||||
CCActionInterval* reverse();
|
CCActionInterval* reverse();
|
||||||
|
|
||||||
std::string key_;
|
std::string m_strKey;
|
||||||
float from_, to_;
|
float m_fFrom, m_fTo;
|
||||||
float delta_;
|
float m_fDelta;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -24,9 +24,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "CCControlScene.h"
|
#include "CCControlScene.h"
|
||||||
|
|
||||||
#include "CCControlSceneManager.h"
|
#include "CCControlSceneManager.h"
|
||||||
|
#include "../ExtensionsTest.h"
|
||||||
|
|
||||||
CCControlScene::CCControlScene()
|
CCControlScene::CCControlScene()
|
||||||
: m_pSceneTitleLabel(NULL)
|
: m_pSceneTitleLabel(NULL)
|
||||||
|
@ -46,6 +45,13 @@ bool CCControlScene::init()
|
||||||
// Get the sceensize
|
// Get the sceensize
|
||||||
CCSize screensize = CCDirector::sharedDirector()->getWinSize();
|
CCSize screensize = CCDirector::sharedDirector()->getWinSize();
|
||||||
|
|
||||||
|
CCMenuItemFont* pBackItem = CCMenuItemFont::itemWithString("Back", this,
|
||||||
|
menu_selector(CCControlScene::toExtensionsMainLayer));
|
||||||
|
pBackItem->setPosition(ccp(screensize.width - 50, 25));
|
||||||
|
CCMenu* pBackMenu = CCMenu::menuWithItems(pBackItem, NULL);
|
||||||
|
pBackMenu->setPosition( CCPointZero );
|
||||||
|
addChild(pBackMenu, 10);
|
||||||
|
|
||||||
// Add the generated background
|
// Add the generated background
|
||||||
CCSprite *background = CCSprite::spriteWithFile("extensions/background.png");
|
CCSprite *background = CCSprite::spriteWithFile("extensions/background.png");
|
||||||
background->setPosition(ccp(screensize.width / 2, screensize.height / 2));
|
background->setPosition(ccp(screensize.width / 2, screensize.height / 2));
|
||||||
|
@ -74,11 +80,19 @@ bool CCControlScene::init()
|
||||||
item3->setPosition(ccp(screensize.width / 2 + 100, 37));
|
item3->setPosition(ccp(screensize.width / 2 + 100, 37));
|
||||||
|
|
||||||
addChild(menu ,1);
|
addChild(menu ,1);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCControlScene::toExtensionsMainLayer(CCObject* sender)
|
||||||
|
{
|
||||||
|
ExtensionsTestScene* pScene = new ExtensionsTestScene();
|
||||||
|
pScene->runThisTest();
|
||||||
|
pScene->release();
|
||||||
|
}
|
||||||
|
|
||||||
void CCControlScene::previousCallback(CCObject* sender)
|
void CCControlScene::previousCallback(CCObject* sender)
|
||||||
{
|
{
|
||||||
CCDirector::sharedDirector()->replaceScene(CCControlSceneManager::sharedControlSceneManager()->previousControlScene());
|
CCDirector::sharedDirector()->replaceScene(CCControlSceneManager::sharedControlSceneManager()->previousControlScene());
|
||||||
|
|
|
@ -59,6 +59,7 @@ public:
|
||||||
~CCControlScene();
|
~CCControlScene();
|
||||||
bool init();
|
bool init();
|
||||||
// Menu Callbacks
|
// Menu Callbacks
|
||||||
|
void toExtensionsMainLayer(cocos2d::CCObject* sender);
|
||||||
void previousCallback(cocos2d::CCObject* sender);
|
void previousCallback(cocos2d::CCObject* sender);
|
||||||
void restartCallback(cocos2d::CCObject* sender);
|
void restartCallback(cocos2d::CCObject* sender);
|
||||||
void nextCallback(cocos2d::CCObject* sender);
|
void nextCallback(cocos2d::CCObject* sender);
|
||||||
|
|
|
@ -5,7 +5,7 @@ enum {
|
||||||
kTagAnimationDance = 1,
|
kTagAnimationDance = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAX_TESTS 8
|
#define MAX_TESTS 11
|
||||||
static int sceneIdx = -1;
|
static int sceneIdx = -1;
|
||||||
|
|
||||||
CCLayer* nextSchedulerTest();
|
CCLayer* nextSchedulerTest();
|
||||||
|
@ -19,20 +19,26 @@ CCLayer* createSchedulerTest(int nIndex)
|
||||||
switch (nIndex)
|
switch (nIndex)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
pLayer = new SchedulerAutoremove(); break;
|
pLayer = new SchedulerDelayAndRepeat(); break;
|
||||||
case 1:
|
case 1:
|
||||||
pLayer = new SchedulerPauseResume(); break;
|
pLayer = new SchedulerTimeScale(); break;
|
||||||
case 2:
|
case 2:
|
||||||
pLayer = new SchedulerUnscheduleAll(); break;
|
pLayer = new TwoSchedulers(); break;
|
||||||
case 3:
|
case 3:
|
||||||
pLayer = new SchedulerUnscheduleAllHard(); break;
|
pLayer = new SchedulerAutoremove(); break;
|
||||||
case 4:
|
case 4:
|
||||||
pLayer = new SchedulerSchedulesAndRemove(); break;
|
pLayer = new SchedulerPauseResume(); break;
|
||||||
case 5:
|
case 5:
|
||||||
pLayer = new SchedulerUpdate(); break;
|
pLayer = new SchedulerUnscheduleAll(); break;
|
||||||
case 6:
|
case 6:
|
||||||
pLayer = new SchedulerUpdateAndCustom(); break;
|
pLayer = new SchedulerUnscheduleAllHard(); break;
|
||||||
case 7:
|
case 7:
|
||||||
|
pLayer = new SchedulerSchedulesAndRemove(); break;
|
||||||
|
case 8:
|
||||||
|
pLayer = new SchedulerUpdate(); break;
|
||||||
|
case 9:
|
||||||
|
pLayer = new SchedulerUpdateAndCustom(); break;
|
||||||
|
case 10:
|
||||||
pLayer = new SchedulerUpdateFromCustom(); break;
|
pLayer = new SchedulerUpdateFromCustom(); break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -591,6 +597,273 @@ void RescheduleSelector::schedUpdate(ccTime dt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SchedulerDelayAndRepeat
|
||||||
|
|
||||||
|
void SchedulerDelayAndRepeat::onEnter()
|
||||||
|
{
|
||||||
|
SchedulerTestLayer::onEnter();
|
||||||
|
schedule(schedule_selector(SchedulerDelayAndRepeat::update), 0, 4 , 3.f);
|
||||||
|
CCLOG("update is scheduled should begin after 3 seconds");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SchedulerDelayAndRepeat::title()
|
||||||
|
{
|
||||||
|
return "Schedule with delay of 3 sec, repeat 4 times";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SchedulerDelayAndRepeat::subtitle()
|
||||||
|
{
|
||||||
|
return "After 5 x executed, method unscheduled. See console";
|
||||||
|
}
|
||||||
|
|
||||||
|
void SchedulerDelayAndRepeat::update(ccTime dt)
|
||||||
|
{
|
||||||
|
CCLog("update called:%f", dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SchedulerTimeScale
|
||||||
|
|
||||||
|
CCControlSlider* SchedulerTimeScale::sliderCtl()
|
||||||
|
{
|
||||||
|
CCControlSlider * slider = CCControlSlider::sliderWithFiles("extensions/sliderTrack2.png","extensions/sliderProgress2.png" ,"extensions/sliderThumb.png");
|
||||||
|
|
||||||
|
slider->addTargetWithActionForControlEvents(this, menu_selector(SchedulerTimeScale::sliderAction), CCControlEventValueChanged);
|
||||||
|
|
||||||
|
slider->setMinimumValue(-3.0f);
|
||||||
|
slider->setMaximumValue(3.0f);
|
||||||
|
slider->setValue(1.0f);
|
||||||
|
|
||||||
|
return slider;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SchedulerTimeScale::sliderAction(CCObject* pSender)
|
||||||
|
{
|
||||||
|
CCControlSlider* pSliderCtl = (CCControlSlider*)pSender;
|
||||||
|
ccTime scale;
|
||||||
|
scale = pSliderCtl->getValue();
|
||||||
|
|
||||||
|
CCDirector::sharedDirector()->getScheduler()->setTimeScale(scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SchedulerTimeScale::onEnter()
|
||||||
|
{
|
||||||
|
SchedulerTestLayer::onEnter();
|
||||||
|
|
||||||
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||||
|
|
||||||
|
// rotate and jump
|
||||||
|
CCActionInterval *jump1 = CCJumpBy::actionWithDuration(4, ccp(-s.width+80,0), 100, 4);
|
||||||
|
CCActionInterval *jump2 = jump1->reverse();
|
||||||
|
CCActionInterval *rot1 = CCRotateBy::actionWithDuration(4, 360*2);
|
||||||
|
CCActionInterval *rot2 = rot1->reverse();
|
||||||
|
|
||||||
|
CCFiniteTimeAction* seq3_1 = CCSequence::actions(jump2, jump1, NULL);
|
||||||
|
CCFiniteTimeAction* seq3_2 = CCSequence::actions(rot1, rot2, NULL);
|
||||||
|
CCFiniteTimeAction* spawn = CCSpawn::actions(seq3_1, seq3_2, NULL);
|
||||||
|
CCRepeat* action = CCRepeat::actionWithAction(spawn, 50);
|
||||||
|
|
||||||
|
CCRepeat* action2 = (CCRepeat*)action->copy()->autorelease();
|
||||||
|
CCRepeat* action3 = (CCRepeat*)action->copy()->autorelease();
|
||||||
|
|
||||||
|
CCSprite *grossini = CCSprite::spriteWithFile("Images/grossini.png");
|
||||||
|
CCSprite *tamara = CCSprite::spriteWithFile("Images/grossinis_sister1.png");
|
||||||
|
CCSprite *kathia = CCSprite::spriteWithFile("Images/grossinis_sister2.png");
|
||||||
|
|
||||||
|
grossini->setPosition(ccp(40,80));
|
||||||
|
tamara->setPosition(ccp(40,80));
|
||||||
|
kathia->setPosition(ccp(40,80));
|
||||||
|
|
||||||
|
addChild(grossini);
|
||||||
|
addChild(tamara);
|
||||||
|
addChild(kathia);
|
||||||
|
|
||||||
|
grossini->runAction(CCSpeed::actionWithAction(action, 0.5f));
|
||||||
|
tamara->runAction(CCSpeed::actionWithAction(action2, 1.5f));
|
||||||
|
kathia->runAction(CCSpeed::actionWithAction(action3, 1.0f));
|
||||||
|
|
||||||
|
CCParticleSystem *emitter = CCParticleFireworks::node();
|
||||||
|
emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_stars1) );
|
||||||
|
addChild(emitter);
|
||||||
|
|
||||||
|
m_pSliderCtl = sliderCtl();
|
||||||
|
m_pSliderCtl->setPosition(ccp(s.width / 2.0f, s.height / 3.0f));
|
||||||
|
|
||||||
|
addChild(m_pSliderCtl);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SchedulerTimeScale::onExit()
|
||||||
|
{
|
||||||
|
// restore scale
|
||||||
|
CCDirector::sharedDirector()->getScheduler()->setTimeScale(1);
|
||||||
|
SchedulerTestLayer::onExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SchedulerTimeScale::title()
|
||||||
|
{
|
||||||
|
return "Scheduler timeScale Test";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SchedulerTimeScale::subtitle()
|
||||||
|
{
|
||||||
|
return "Fast-forward and rewind using scheduler.timeScale";
|
||||||
|
}
|
||||||
|
|
||||||
|
//TwoSchedulers
|
||||||
|
|
||||||
|
CCControlSlider *TwoSchedulers::sliderCtl()
|
||||||
|
{
|
||||||
|
// CGRect frame = CGRectMake(12.0f, 12.0f, 120.0f, 7.0f);
|
||||||
|
CCControlSlider *slider = CCControlSlider::sliderWithFiles("extensions/sliderTrack2.png","extensions/sliderProgress2.png" ,"extensions/sliderThumb.png");
|
||||||
|
//[[UISlider alloc] initWithFrame:frame];
|
||||||
|
slider->addTargetWithActionForControlEvents(this, menu_selector(TwoSchedulers::sliderAction), CCControlEventValueChanged);
|
||||||
|
|
||||||
|
// in case the parent view draws with a custom color or gradient, use a transparent color
|
||||||
|
//slider.backgroundColor = [UIColor clearColor];
|
||||||
|
|
||||||
|
slider->setMinimumValue(0.0f);
|
||||||
|
slider->setMaximumValue(2.0f);
|
||||||
|
//slider.continuous = YES;
|
||||||
|
slider->setValue(1.0f);
|
||||||
|
|
||||||
|
return slider;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TwoSchedulers::sliderAction(CCObject* sender)
|
||||||
|
{
|
||||||
|
ccTime scale;
|
||||||
|
|
||||||
|
CCControlSlider *slider = (CCControlSlider*) sender;
|
||||||
|
scale = slider->getValue();
|
||||||
|
|
||||||
|
if( sender == sliderCtl1 )
|
||||||
|
sched1->setTimeScale(scale);
|
||||||
|
else
|
||||||
|
sched2->setTimeScale(scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TwoSchedulers::onEnter()
|
||||||
|
{
|
||||||
|
SchedulerTestLayer::onEnter();
|
||||||
|
|
||||||
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||||
|
|
||||||
|
// rotate and jump
|
||||||
|
CCActionInterval *jump1 = CCJumpBy::actionWithDuration(4, ccp(0,0), 100, 4);
|
||||||
|
CCActionInterval *jump2 = jump1->reverse();
|
||||||
|
|
||||||
|
CCFiniteTimeAction* seq = CCSequence::actions(jump2, jump1, NULL);
|
||||||
|
CCRepeatForever* action = CCRepeatForever::actionWithAction((CCActionInterval *)seq);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Center
|
||||||
|
//
|
||||||
|
CCSprite *grossini = CCSprite::spriteWithFile("Images/grossini.png");
|
||||||
|
addChild(grossini);
|
||||||
|
grossini->setPosition(ccp(s.width/2,100));
|
||||||
|
grossini->runAction((CCAction*)action->copy()->autorelease());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CCScheduler *defaultScheduler = CCDirector::sharedDirector()->getScheduler();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Left:
|
||||||
|
//
|
||||||
|
|
||||||
|
// Create a new scheduler, and link it to the main scheduler
|
||||||
|
sched1 = new CCScheduler();
|
||||||
|
|
||||||
|
defaultScheduler->scheduleUpdateForTarget(sched1, 0, false);
|
||||||
|
|
||||||
|
// Create a new ActionManager, and link it to the new scheudler
|
||||||
|
actionManager1 = new CCActionManager();
|
||||||
|
sched1->scheduleUpdateForTarget(actionManager1, 0, false);
|
||||||
|
|
||||||
|
for( unsigned int i=0; i < 10; i++ )
|
||||||
|
{
|
||||||
|
CCSprite *sprite = CCSprite::spriteWithFile("Images/grossinis_sister1.png");
|
||||||
|
|
||||||
|
// IMPORTANT: Set the actionManager running any action
|
||||||
|
sprite->setActionManager(actionManager1);
|
||||||
|
|
||||||
|
addChild(sprite);
|
||||||
|
sprite->setPosition(ccp(30+15*i,100));
|
||||||
|
|
||||||
|
sprite->runAction((CCAction*)action->copy()->autorelease());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Right:
|
||||||
|
//
|
||||||
|
|
||||||
|
// Create a new scheduler, and link it to the main scheduler
|
||||||
|
sched2 = new CCScheduler();;
|
||||||
|
defaultScheduler->scheduleUpdateForTarget(sched2, 0, false);
|
||||||
|
|
||||||
|
// Create a new ActionManager, and link it to the new scheudler
|
||||||
|
actionManager2 = new CCActionManager();
|
||||||
|
sched2->scheduleUpdateForTarget(actionManager2, 0, false);
|
||||||
|
|
||||||
|
for( unsigned int i=0; i < 10; i++ ) {
|
||||||
|
CCSprite *sprite = CCSprite::spriteWithFile("Images/grossinis_sister2.png");
|
||||||
|
|
||||||
|
// IMPORTANT: Set the actionManager running any action
|
||||||
|
sprite->setActionManager(actionManager2);
|
||||||
|
|
||||||
|
addChild(sprite);
|
||||||
|
sprite->setPosition(ccp(s.width-30-15*i,100));
|
||||||
|
|
||||||
|
sprite->runAction((CCAction*)action->copy()->autorelease());
|
||||||
|
}
|
||||||
|
|
||||||
|
sliderCtl1 = sliderCtl();
|
||||||
|
addChild(sliderCtl1);
|
||||||
|
sliderCtl1->retain();
|
||||||
|
sliderCtl1->setPosition(ccp(s.width / 4.0f, s.height - 20));
|
||||||
|
|
||||||
|
sliderCtl2 = sliderCtl();
|
||||||
|
addChild(sliderCtl2);
|
||||||
|
sliderCtl2->retain();
|
||||||
|
sliderCtl2->setPosition(ccp(s.width / 4.0f*3.0f, s.height-20));
|
||||||
|
// #ifdef __CC_PLATFORM_IOS
|
||||||
|
// CGRect frame = [sliderCtl2 frame];
|
||||||
|
// #elif defined(__CC_PLATFORM_MAC)
|
||||||
|
// NSRect frame = [sliderCtl2 frame];
|
||||||
|
// #endif
|
||||||
|
// frame.origin.x += 300;
|
||||||
|
// [sliderCtl2 setFrame:frame];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TwoSchedulers::~TwoSchedulers()
|
||||||
|
{
|
||||||
|
CCScheduler *defaultScheduler = CCDirector::sharedDirector()->getScheduler();
|
||||||
|
defaultScheduler->unscheduleAllSelectorsForTarget(sched1);
|
||||||
|
defaultScheduler->unscheduleAllSelectorsForTarget(sched2);
|
||||||
|
|
||||||
|
sliderCtl1->release();
|
||||||
|
sliderCtl2->release();
|
||||||
|
|
||||||
|
sched1->release();
|
||||||
|
sched2->release();
|
||||||
|
|
||||||
|
actionManager1->release();
|
||||||
|
actionManager2->release();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TwoSchedulers::title()
|
||||||
|
{
|
||||||
|
return "Two custom schedulers";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TwoSchedulers::subtitle()
|
||||||
|
{
|
||||||
|
return "Three schedulers. 2 custom + 1 default. Two different time scales";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// SchedulerTestScene
|
// SchedulerTestScene
|
||||||
|
|
|
@ -154,6 +154,47 @@ private:
|
||||||
int m_nTicks;
|
int m_nTicks;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SchedulerDelayAndRepeat : public SchedulerTestLayer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void onEnter();
|
||||||
|
virtual std::string title();
|
||||||
|
virtual std::string subtitle();
|
||||||
|
void update(ccTime dt);
|
||||||
|
};
|
||||||
|
|
||||||
|
class SchedulerTimeScale : public SchedulerTestLayer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void onEnter();
|
||||||
|
void onExit();
|
||||||
|
virtual std::string title();
|
||||||
|
virtual std::string subtitle();
|
||||||
|
CCControlSlider* sliderCtl();
|
||||||
|
void sliderAction(CCObject* pSender);
|
||||||
|
CCControlSlider* m_pSliderCtl;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class TwoSchedulers : public SchedulerTestLayer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~TwoSchedulers();
|
||||||
|
virtual std::string title();
|
||||||
|
virtual std::string subtitle();
|
||||||
|
void onEnter();
|
||||||
|
CCControlSlider* sliderCtl();
|
||||||
|
void sliderAction(CCObject* sender);
|
||||||
|
CCScheduler *sched1;
|
||||||
|
CCScheduler *sched2;
|
||||||
|
CCActionManager *actionManager1;
|
||||||
|
CCActionManager *actionManager2;
|
||||||
|
|
||||||
|
CCControlSlider *sliderCtl1;
|
||||||
|
CCControlSlider *sliderCtl2;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class SchedulerTestScene : public TestScene
|
class SchedulerTestScene : public TestScene
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
static int sceneIdx = -1;
|
static int sceneIdx = -1;
|
||||||
|
|
||||||
#define MAX_LAYER 7
|
#define MAX_LAYER 8
|
||||||
|
|
||||||
static CCLayer* createShaderLayer(int nIndex)
|
static CCLayer* createShaderLayer(int nIndex)
|
||||||
{
|
{
|
||||||
|
@ -17,6 +17,7 @@ static CCLayer* createShaderLayer(int nIndex)
|
||||||
case 4: return new ShaderFlower();
|
case 4: return new ShaderFlower();
|
||||||
case 5: return new ShaderPlasma();
|
case 5: return new ShaderPlasma();
|
||||||
case 6: return new ShaderBlur();
|
case 6: return new ShaderBlur();
|
||||||
|
case 7: return new ShaderRetroEffect();
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -576,6 +577,7 @@ CCControlSlider* ShaderBlur::createSliderCtl()
|
||||||
slider->setAnchorPoint(ccp(0.5f, 1.0f));
|
slider->setAnchorPoint(ccp(0.5f, 1.0f));
|
||||||
slider->setMinimumValue(0.0f); // Sets the min value of range
|
slider->setMinimumValue(0.0f); // Sets the min value of range
|
||||||
slider->setMaximumValue(3.0f); // Sets the max value of range
|
slider->setMaximumValue(3.0f); // Sets the max value of range
|
||||||
|
slider->setValue(1.0f);
|
||||||
slider->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 3.0f));
|
slider->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 3.0f));
|
||||||
|
|
||||||
// When the value of the slider will change, the given selector will be call
|
// When the value of the slider will change, the given selector will be call
|
||||||
|
@ -589,20 +591,20 @@ bool ShaderBlur::init()
|
||||||
{
|
{
|
||||||
if( ShaderTestDemo::init() )
|
if( ShaderTestDemo::init() )
|
||||||
{
|
{
|
||||||
blurSprite = SpriteBlur::spriteWithFile("Images/grossini.png");
|
m_pBlurSprite = SpriteBlur::spriteWithFile("Images/grossini.png");
|
||||||
|
|
||||||
CCSprite *sprite = CCSprite::spriteWithFile("Images/grossini.png");
|
CCSprite *sprite = CCSprite::spriteWithFile("Images/grossini.png");
|
||||||
|
|
||||||
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||||
blurSprite->setPosition(ccp(s.width/3, s.height/2));
|
m_pBlurSprite->setPosition(ccp(s.width/3, s.height/2));
|
||||||
sprite->setPosition(ccp(2*s.width/3, s.height/2));
|
sprite->setPosition(ccp(2*s.width/3, s.height/2));
|
||||||
|
|
||||||
addChild(blurSprite);
|
addChild(m_pBlurSprite);
|
||||||
addChild(sprite);
|
addChild(sprite);
|
||||||
|
|
||||||
sliderCtl = createSliderCtl();
|
m_pSliderCtl = createSliderCtl();
|
||||||
|
|
||||||
addChild(sliderCtl);
|
addChild(m_pSliderCtl);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -612,7 +614,84 @@ bool ShaderBlur::init()
|
||||||
void ShaderBlur::sliderAction(CCObject* sender)
|
void ShaderBlur::sliderAction(CCObject* sender)
|
||||||
{
|
{
|
||||||
CCControlSlider* pSlider = (CCControlSlider*)sender;
|
CCControlSlider* pSlider = (CCControlSlider*)sender;
|
||||||
blurSprite->setBlurSize(pSlider->getValue());
|
m_pBlurSprite->setBlurSize(pSlider->getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShaderRetroEffect
|
||||||
|
|
||||||
|
ShaderRetroEffect::ShaderRetroEffect()
|
||||||
|
: m_pLabel(NULL)
|
||||||
|
, m_fAccum(0.0f)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShaderRetroEffect::init()
|
||||||
|
{
|
||||||
|
if( ShaderTestDemo::init() ) {
|
||||||
|
|
||||||
|
GLchar * fragSource = (GLchar*) CCString::stringWithContentsOfFile(CCFileUtils::fullPathFromRelativePath("Shaders/example_HorizontalColor.fsh"))->getCString();
|
||||||
|
CCGLProgram *p = new CCGLProgram();
|
||||||
|
p->initWithVertexShaderByteArray(ccPositionTexture_vert, fragSource);
|
||||||
|
|
||||||
|
p->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
|
||||||
|
p->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
|
||||||
|
|
||||||
|
p->link();
|
||||||
|
p->updateUniforms();
|
||||||
|
|
||||||
|
|
||||||
|
CCDirector *director = CCDirector::sharedDirector();
|
||||||
|
CCSize s = director->getWinSize();
|
||||||
|
|
||||||
|
m_pLabel = CCLabelBMFont::labelWithString("RETRO EFFECT", "fonts/west_england-64.fnt");
|
||||||
|
|
||||||
|
m_pLabel->setShaderProgram(p);
|
||||||
|
|
||||||
|
p->release();
|
||||||
|
|
||||||
|
|
||||||
|
m_pLabel->setPosition(ccp(s.width/2,s.height/2));
|
||||||
|
|
||||||
|
addChild(m_pLabel);
|
||||||
|
|
||||||
|
scheduleUpdate();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderRetroEffect::update(ccTime dt)
|
||||||
|
{
|
||||||
|
m_fAccum += dt;
|
||||||
|
|
||||||
|
CCArray* pArray = m_pLabel->getChildren();
|
||||||
|
|
||||||
|
int i=0;
|
||||||
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(pArray, pObj)
|
||||||
|
{
|
||||||
|
CCSprite *sprite = (CCSprite*)pObj;
|
||||||
|
i++;
|
||||||
|
CCPoint oldPosition = sprite->getPosition();
|
||||||
|
sprite->setPosition(ccp( oldPosition.x, sinf( m_fAccum * 2 + i/2.0) * 20 ));
|
||||||
|
|
||||||
|
// add fabs() to prevent negative scaling
|
||||||
|
float scaleY = ( sinf( m_fAccum * 2 + i/2.0 + 0.707) );
|
||||||
|
|
||||||
|
sprite->setScaleY(scaleY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ShaderRetroEffect::title()
|
||||||
|
{
|
||||||
|
return "Shader: Retro test";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ShaderRetroEffect::subtitle()
|
||||||
|
{
|
||||||
|
return "sin() effect with moving colors";
|
||||||
}
|
}
|
||||||
|
|
||||||
///---------------------------------------
|
///---------------------------------------
|
||||||
|
|
|
@ -91,11 +91,22 @@ public:
|
||||||
CCControlSlider* createSliderCtl();
|
CCControlSlider* createSliderCtl();
|
||||||
void sliderAction(CCObject* sender);
|
void sliderAction(CCObject* sender);
|
||||||
protected:
|
protected:
|
||||||
SpriteBlur *blurSprite;
|
SpriteBlur* m_pBlurSprite;
|
||||||
CCControlSlider* sliderCtl;
|
CCControlSlider* m_pSliderCtl;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// can not implement SpriteBlur, because we don't have slider now
|
class ShaderRetroEffect : public ShaderTestDemo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ShaderRetroEffect();
|
||||||
|
virtual std::string title();
|
||||||
|
virtual std::string subtitle();
|
||||||
|
bool init();
|
||||||
|
void update(ccTime dt);
|
||||||
|
protected:
|
||||||
|
CCLabelBMFont* m_pLabel;
|
||||||
|
ccTime m_fAccum;
|
||||||
|
};
|
||||||
|
|
||||||
class ShaderNode : public CCNode
|
class ShaderNode : public CCNode
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue