2012-04-08 14:16:29 +08:00
|
|
|
#include "MotionStreakTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
2012-06-12 16:56:34 +08:00
|
|
|
enum {
|
|
|
|
kTagLabel = 1,
|
|
|
|
kTagSprite1 = 2,
|
|
|
|
kTagSprite2 = 3,
|
|
|
|
};
|
|
|
|
|
2011-07-08 15:57:46 +08:00
|
|
|
CCLayer* nextMotionAction();
|
|
|
|
CCLayer* backMotionAction();
|
2012-04-08 14:16:29 +08:00
|
|
|
CCLayer* restartMotionAction();
|
|
|
|
|
2010-08-25 17:02:58 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// MotionStreakTest1
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2010-08-25 17:02:58 +08:00
|
|
|
void MotionStreakTest1::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
MotionStreakTest::onEnter();
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// the root object just rotates around
|
2012-06-14 15:13:16 +08:00
|
|
|
m_root = CCSprite::create(s_pPathR1);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(m_root, 1);
|
2012-06-12 16:56:34 +08:00
|
|
|
m_root->setPosition(ccp(s.width/2, s.height/2));
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// the target object is offset from root, and the streak is moved to follow it
|
2012-06-14 15:13:16 +08:00
|
|
|
m_target = CCSprite::create(s_pPathR1);
|
2012-04-19 14:35:52 +08:00
|
|
|
m_root->addChild(m_target);
|
2012-06-12 16:56:34 +08:00
|
|
|
m_target->setPosition(ccp(s.width/4, 0));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// create the streak object and add it to the scene
|
2012-06-14 15:13:16 +08:00
|
|
|
streak = CCMotionStreak::create(2, 3, 32, ccGREEN, s_streak);
|
2012-06-12 16:56:34 +08:00
|
|
|
addChild(streak);
|
2012-04-19 14:35:52 +08:00
|
|
|
// schedule an update on each frame so we can syncronize the streak with the target
|
|
|
|
schedule(schedule_selector(MotionStreakTest1::onUpdate));
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCActionInterval* a1 = CCRotateBy::create(2, 360);
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCAction* action1 = CCRepeatForever::create(a1);
|
|
|
|
CCActionInterval* motion = CCMoveBy::create(2, CCPointMake(100,0) );
|
|
|
|
m_root->runAction( CCRepeatForever::create((CCActionInterval*)(CCSequence::create(motion, motion->reverse(), NULL)) ) );
|
2012-04-19 14:35:52 +08:00
|
|
|
m_root->runAction( action1 );
|
2012-03-22 14:32:32 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCActionInterval *colorAction = CCRepeatForever::create((CCActionInterval *)CCSequence::create(
|
|
|
|
CCTintTo::create(0.2f, 255, 0, 0),
|
|
|
|
CCTintTo::create(0.2f, 0, 255, 0),
|
|
|
|
CCTintTo::create(0.2f, 0, 0, 255),
|
|
|
|
CCTintTo::create(0.2f, 0, 255, 255),
|
|
|
|
CCTintTo::create(0.2f, 255, 255, 0),
|
|
|
|
CCTintTo::create(0.2f, 255, 0, 255),
|
|
|
|
CCTintTo::create(0.2f, 255, 255, 255),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL));
|
2012-03-22 14:32:32 +08:00
|
|
|
|
2012-06-12 16:56:34 +08:00
|
|
|
streak->runAction(colorAction);
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void MotionStreakTest1::onUpdate(float delta)
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2012-06-12 16:56:34 +08:00
|
|
|
streak->setPosition( m_target->convertToWorldSpace(CCPointZero) );
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2010-08-25 17:02:58 +08:00
|
|
|
std::string MotionStreakTest1::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "MotionStreak test 1";
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2010-08-25 17:02:58 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// MotionStreakTest2
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2010-08-25 17:02:58 +08:00
|
|
|
void MotionStreakTest2::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
MotionStreakTest::onEnter();
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
setTouchEnabled(true);
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
|
|
|
|
// create the streak object and add it to the scene
|
2012-06-14 15:13:16 +08:00
|
|
|
streak = CCMotionStreak::create(3, 3, 64, ccWHITE, s_streak );
|
2012-06-12 16:56:34 +08:00
|
|
|
addChild(streak);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-12 16:56:34 +08:00
|
|
|
streak->setPosition( CCPointMake(s.width/2, s.height/2) );
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2011-03-18 09:39:34 +08:00
|
|
|
void MotionStreakTest2::ccTouchesMoved(CCSet* touches, CCEvent* event)
|
2010-08-25 17:02:58 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSetIterator it = touches->begin();
|
2010-08-31 17:04:20 +08:00
|
|
|
CCTouch* touch = (CCTouch*)(*it);
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCPoint touchLocation = touch->locationInView();
|
|
|
|
touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );
|
|
|
|
|
2012-06-12 16:56:34 +08:00
|
|
|
streak->setPosition( touchLocation );
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2010-08-25 17:02:58 +08:00
|
|
|
std::string MotionStreakTest2::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "MotionStreak test";
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2012-06-12 16:56:34 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Issue1358
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
void Issue1358::onEnter()
|
|
|
|
{
|
|
|
|
MotionStreakTest::onEnter();
|
|
|
|
|
|
|
|
// ask director the the window size
|
|
|
|
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
streak = CCMotionStreak::create(2.0f, 1.0f, 50.0f, ccc3(255, 255, 0), "Images/Icon.png");
|
2012-06-12 16:56:34 +08:00
|
|
|
addChild(streak);
|
|
|
|
|
|
|
|
|
|
|
|
m_center = ccp(size.width/2, size.height/2);
|
|
|
|
m_fRadius = size.width/3;
|
|
|
|
m_fAngle = 0.0f;
|
|
|
|
|
|
|
|
schedule(schedule_selector(Issue1358::update), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Issue1358::update(float dt)
|
|
|
|
{
|
|
|
|
m_fAngle += 1.0f;
|
|
|
|
streak->setPosition(ccp(m_center.x + cosf(m_fAngle/180 * M_PI)*m_fRadius,
|
|
|
|
m_center.y + sinf(m_fAngle/ 180 * M_PI)*m_fRadius));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Issue1358::title()
|
|
|
|
{
|
|
|
|
return "Issue 1358";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Issue1358::subtitle()
|
|
|
|
{
|
|
|
|
return "The tail should use the texture";
|
|
|
|
}
|
|
|
|
|
2010-08-25 17:02:58 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// MotionStreakTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2012-04-08 14:16:29 +08:00
|
|
|
|
|
|
|
// enum
|
|
|
|
// {
|
2012-04-19 14:35:52 +08:00
|
|
|
// IDC_NEXT = 100,
|
|
|
|
// IDC_BACK,
|
|
|
|
// IDC_RESTART
|
2012-04-08 14:16:29 +08:00
|
|
|
// };
|
|
|
|
|
|
|
|
static int sceneIdx = -1;
|
|
|
|
|
2012-06-12 16:56:34 +08:00
|
|
|
#define MAX_LAYER 3
|
2010-08-25 17:02:58 +08:00
|
|
|
|
|
|
|
CCLayer* createMotionLayer(int nIndex)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
switch(nIndex)
|
|
|
|
{
|
|
|
|
case 0: return new MotionStreakTest1();
|
|
|
|
case 1: return new MotionStreakTest2();
|
2012-06-12 16:56:34 +08:00
|
|
|
case 2: return new Issue1358();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return NULL;
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCLayer* nextMotionAction()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx++;
|
|
|
|
sceneIdx = sceneIdx % MAX_LAYER;
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLayer* pLayer = createMotionLayer(sceneIdx);
|
|
|
|
pLayer->autorelease();
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return pLayer;
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCLayer* backMotionAction()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx--;
|
|
|
|
int total = MAX_LAYER;
|
|
|
|
if( sceneIdx < 0 )
|
|
|
|
sceneIdx += total;
|
|
|
|
|
|
|
|
CCLayer* pLayer = createMotionLayer(sceneIdx);
|
|
|
|
pLayer->autorelease();
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return pLayer;
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCLayer* restartMotionAction()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLayer* pLayer = createMotionLayer(sceneIdx);
|
|
|
|
pLayer->autorelease();
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return pLayer;
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MotionStreakTest::MotionStreakTest(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MotionStreakTest::~MotionStreakTest(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-08-25 17:02:58 +08:00
|
|
|
std::string MotionStreakTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "No title";
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|
|
|
|
|
2012-06-12 16:56:34 +08:00
|
|
|
std::string MotionStreakTest::subtitle()
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2010-08-25 17:02:58 +08:00
|
|
|
void MotionStreakTest::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLayer::onEnter();
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Arial", 32);
|
2012-06-12 16:56:34 +08:00
|
|
|
addChild(label, 0, kTagLabel);
|
|
|
|
label->setPosition(CCPointMake(s.width/2, s.height-50));
|
|
|
|
|
|
|
|
string subTitle = this->subtitle();
|
|
|
|
if (subTitle.size() > 0)
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLabelTTF *l = CCLabelTTF::create(subTitle.c_str(), "Thonburi", 16);
|
2012-06-12 16:56:34 +08:00
|
|
|
addChild(l, 1);
|
|
|
|
l->setPosition(ccp(s.width/2, s.height-80));
|
|
|
|
}
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(MotionStreakTest::backCallback) );
|
|
|
|
CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(MotionStreakTest::restartCallback) );
|
|
|
|
CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(MotionStreakTest::nextCallback) );
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenu *menu = CCMenu::create(item1, item2, item3, NULL);
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-06-12 16:56:34 +08:00
|
|
|
menu->setPosition(CCPointZero);
|
|
|
|
item1->setPosition(CCPointMake(s.width/2 - item2->getContentSize().width*2, item2->getContentSize().height/2));
|
|
|
|
item2->setPosition(CCPointMake(s.width/2, item2->getContentSize().height/2));
|
|
|
|
item3->setPosition(CCPointMake(s.width/2 + item2->getContentSize().width*2, item2->getContentSize().height/2));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
addChild(menu, 1);
|
2012-03-22 14:32:32 +08:00
|
|
|
|
2012-07-23 22:49:11 +08:00
|
|
|
CCMenuItemToggle *itemMode = CCMenuItemToggle::createWithTarget(this, menu_selector(MotionStreakTest::modeCallback),
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont::create("Use High Quality Mode"),
|
|
|
|
CCMenuItemFont::create("Use Fast Mode"),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL);
|
2012-03-22 14:32:32 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenu *menuMode = CCMenu::create(itemMode, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(menuMode);
|
2012-03-22 14:32:32 +08:00
|
|
|
|
2012-06-12 16:56:34 +08:00
|
|
|
menuMode->setPosition(ccp(s.width/2, s.height/4));
|
2012-03-22 14:32:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MotionStreakTest::modeCallback(CCObject *pSender)
|
|
|
|
{
|
2012-06-15 17:39:13 +08:00
|
|
|
bool fastMode = streak->isFastMode();
|
|
|
|
streak->setFastMode(! fastMode);
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void MotionStreakTest::restartCallback(CCObject* pSender)
|
2010-08-25 17:02:58 +08:00
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCScene* s = new MotionStreakTestScene();//CCScene::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild(restartMotionAction());
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCDirector::sharedDirector()->replaceScene(s);
|
2010-09-13 18:04:36 +08:00
|
|
|
s->release();
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void MotionStreakTest::nextCallback(CCObject* pSender)
|
2010-08-25 17:02:58 +08:00
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCScene* s = new MotionStreakTestScene();//CCScene::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild( nextMotionAction() );
|
|
|
|
CCDirector::sharedDirector()->replaceScene(s);
|
2010-09-13 18:04:36 +08:00
|
|
|
s->release();
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void MotionStreakTest::backCallback(CCObject* pSender)
|
2010-08-25 17:02:58 +08:00
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCScene* s = new MotionStreakTestScene;//CCScene::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild( backMotionAction() );
|
|
|
|
CCDirector::sharedDirector()->replaceScene(s);
|
2010-09-13 18:04:36 +08:00
|
|
|
s->release();
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MotionStreakTestScene::runThisTest()
|
|
|
|
{
|
|
|
|
CCLayer* pLayer = nextMotionAction();
|
|
|
|
addChild(pLayer);
|
|
|
|
|
2010-11-11 11:18:58 +08:00
|
|
|
CCDirector::sharedDirector()->replaceScene(this);
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|