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,
|
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* nextMotionAction();
|
|
|
|
Layer* backMotionAction();
|
|
|
|
Layer* restartMotionAction();
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
static int sceneIdx = -1;
|
|
|
|
|
|
|
|
static std::function<Layer*()> createFunctions[] =
|
|
|
|
{
|
|
|
|
CL(MotionStreakTest1),
|
|
|
|
CL(MotionStreakTest2),
|
|
|
|
CL(Issue1358),
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
|
|
|
|
|
|
|
Layer* nextMotionAction()
|
|
|
|
{
|
|
|
|
sceneIdx++;
|
|
|
|
sceneIdx = sceneIdx % MAX_LAYER;
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = (createFunctions[sceneIdx])();
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer* backMotionAction()
|
|
|
|
{
|
|
|
|
sceneIdx--;
|
|
|
|
int total = MAX_LAYER;
|
|
|
|
if( sceneIdx < 0 )
|
|
|
|
sceneIdx += total;
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = (createFunctions[sceneIdx])();
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer* restartMotionAction()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = (createFunctions[sceneIdx])();
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
|
|
|
}
|
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
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// the root object just rotates around
|
2013-07-24 06:20:22 +08:00
|
|
|
_root = Sprite::create(s_pathR1);
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_root, 1);
|
2014-05-15 01:07:09 +08:00
|
|
|
_root->setPosition(Vec2(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
|
2013-07-24 06:20:22 +08:00
|
|
|
_target = Sprite::create(s_pathR1);
|
2013-06-15 14:03:30 +08:00
|
|
|
_root->addChild(_target);
|
2014-05-15 01:07:09 +08:00
|
|
|
_target->setPosition(Vec2(s.width/4, 0));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// create the streak object and add it to the scene
|
2013-07-08 18:11:32 +08:00
|
|
|
streak = MotionStreak::create(2, 3, 32, Color3B::GREEN, 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
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto a1 = RotateBy::create(2, 360);
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto action1 = RepeatForever::create(a1);
|
2014-05-15 01:07:09 +08:00
|
|
|
auto motion = MoveBy::create(2, Vec2(100,0) );
|
2014-07-10 00:45:27 +08:00
|
|
|
_root->runAction( RepeatForever::create(Sequence::create(motion, motion->reverse(), nullptr) ) );
|
2013-06-15 14:03:30 +08:00
|
|
|
_root->runAction( action1 );
|
2012-03-22 14:32:32 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto colorAction = RepeatForever::create(Sequence::create(
|
2013-06-20 14:17:10 +08:00
|
|
|
TintTo::create(0.2f, 255, 0, 0),
|
|
|
|
TintTo::create(0.2f, 0, 255, 0),
|
|
|
|
TintTo::create(0.2f, 0, 0, 255),
|
|
|
|
TintTo::create(0.2f, 0, 255, 255),
|
|
|
|
TintTo::create(0.2f, 255, 255, 0),
|
|
|
|
TintTo::create(0.2f, 255, 0, 255),
|
|
|
|
TintTo::create(0.2f, 255, 255, 255),
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr));
|
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
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
streak->setPosition( _target->convertToWorldSpace(Vec2::ZERO) );
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string MotionStreakTest1::title() const
|
2010-08-25 17:02:58 +08:00
|
|
|
{
|
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
|
|
|
|
2013-10-23 16:14:03 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(MotionStreakTest2::onTouchesMoved, this);
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2013-10-23 16:14:03 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// create the streak object and add it to the scene
|
2013-07-08 18:11:32 +08:00
|
|
|
streak = MotionStreak::create(3, 3, 64, Color3B::WHITE, s_streak );
|
2012-06-12 16:56:34 +08:00
|
|
|
addChild(streak);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
streak->setPosition( Vec2(s.width/2, s.height/2) );
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void MotionStreakTest2::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
|
2010-08-25 17:02:58 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
auto touchLocation = touches[0]->getLocation();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-12 16:56:34 +08:00
|
|
|
streak->setPosition( touchLocation );
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string MotionStreakTest2::title() const
|
2010-08-25 17:02:58 +08:00
|
|
|
{
|
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
|
2013-08-16 16:05:27 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2012-06-12 16:56:34 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
streak = MotionStreak::create(2.0f, 1.0f, 50.0f, Color3B(255, 255, 0), "Images/Icon.png");
|
2012-06-12 16:56:34 +08:00
|
|
|
addChild(streak);
|
|
|
|
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
_center = Vec2(size.width/2, size.height/2);
|
2013-06-15 14:03:30 +08:00
|
|
|
_radius = size.width/3;
|
|
|
|
_angle = 0.0f;
|
2012-06-12 16:56:34 +08:00
|
|
|
|
|
|
|
schedule(schedule_selector(Issue1358::update), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Issue1358::update(float dt)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_angle += 1.0f;
|
2014-05-15 01:07:09 +08:00
|
|
|
streak->setPosition(Vec2(_center.x + cosf(_angle/180 * M_PI)*_radius,
|
2013-06-15 14:03:30 +08:00
|
|
|
_center.y + sinf(_angle/ 180 * M_PI)*_radius));
|
2012-06-12 16:56:34 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue1358::title() const
|
2012-06-12 16:56:34 +08:00
|
|
|
{
|
|
|
|
return "Issue 1358";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue1358::subtitle() const
|
2012-06-12 16:56:34 +08:00
|
|
|
{
|
|
|
|
return "The tail should use the texture";
|
|
|
|
}
|
|
|
|
|
2010-08-25 17:02:58 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// MotionStreakTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2012-04-08 14:16:29 +08:00
|
|
|
|
|
|
|
MotionStreakTest::MotionStreakTest(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MotionStreakTest::~MotionStreakTest(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string MotionStreakTest::title() const
|
2010-08-25 17:02:58 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "No title";
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string MotionStreakTest::subtitle() const
|
2012-06-12 16:56:34 +08:00
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2010-08-25 17:02:58 +08:00
|
|
|
void MotionStreakTest::onEnter()
|
|
|
|
{
|
2013-06-07 08:12:28 +08:00
|
|
|
BaseTest::onEnter();
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto itemMode = MenuItemToggle::createWithCallback( CC_CALLBACK_1(MotionStreakTest::modeCallback, this),
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::create("Use High Quality Mode"),
|
|
|
|
MenuItemFont::create("Use Fast Mode"),
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr);
|
2012-03-22 14:32:32 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto menuMode = Menu::create(itemMode, nullptr);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(menuMode);
|
2012-03-22 14:32:32 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
menuMode->setPosition(Vec2(s.width/2, s.height/4));
|
2012-03-22 14:32:32 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void MotionStreakTest::modeCallback(Ref *pSender)
|
2012-03-22 14:32:32 +08:00
|
|
|
{
|
2012-06-15 17:39:13 +08:00
|
|
|
bool fastMode = streak->isFastMode();
|
|
|
|
streak->setFastMode(! fastMode);
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void MotionStreakTest::restartCallback(Ref* sender)
|
2010-08-25 17:02:58 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
auto s = new (std::nothrow) MotionStreakTestScene();//CCScene::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild(restartMotionAction());
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2010-09-13 18:04:36 +08:00
|
|
|
s->release();
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void MotionStreakTest::nextCallback(Ref* sender)
|
2010-08-25 17:02:58 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
auto s = new (std::nothrow) MotionStreakTestScene();//CCScene::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild( nextMotionAction() );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2010-09-13 18:04:36 +08:00
|
|
|
s->release();
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void MotionStreakTest::backCallback(Ref* sender)
|
2010-08-25 17:02:58 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
auto s = new (std::nothrow) MotionStreakTestScene;//CCScene::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild( backMotionAction() );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2010-09-13 18:04:36 +08:00
|
|
|
s->release();
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MotionStreakTestScene::runThisTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = nextMotionAction();
|
2013-07-23 08:25:44 +08:00
|
|
|
addChild(layer);
|
2010-08-25 17:02:58 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|