2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
http://www.cocos2d-x.org
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "MotionStreakTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
kTagLabel = 1,
|
|
|
|
kTagSprite1 = 2,
|
|
|
|
kTagSprite2 = 3,
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
MotionStreakTests::MotionStreakTests()
|
|
|
|
{
|
|
|
|
ADD_TEST_CASE(MotionStreakTest1);
|
|
|
|
ADD_TEST_CASE(MotionStreakTest2);
|
|
|
|
ADD_TEST_CASE(Issue1358);
|
|
|
|
ADD_TEST_CASE(Issue12226);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// MotionStreakTest1
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
void MotionStreakTest1::onEnter()
|
|
|
|
{
|
|
|
|
MotionStreakTest::onEnter();
|
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// the root object just rotates around
|
|
|
|
_root = Sprite::create(s_pathR1);
|
|
|
|
addChild(_root, 1);
|
2021-12-28 16:06:23 +08:00
|
|
|
_root->setPosition(Vec2(s.width / 2, s.height / 2));
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// the target object is offset from root, and the streak is moved to follow it
|
|
|
|
_target = Sprite::create(s_pathR1);
|
|
|
|
_root->addChild(_target);
|
2021-12-28 16:06:23 +08:00
|
|
|
_target->setPosition(Vec2(s.width / 4, 0.0f));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
// create the streak object and add it to the scene
|
|
|
|
_streak = MotionStreak::create(2, 3, 32, Color3B::GREEN, s_streak);
|
|
|
|
addChild(_streak);
|
|
|
|
// schedule an update on each frame so we can synchronize the streak with the target
|
|
|
|
schedule(CC_SCHEDULE_SELECTOR(MotionStreakTest1::onUpdate));
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto a1 = RotateBy::create(2, 360);
|
|
|
|
|
|
|
|
auto action1 = RepeatForever::create(a1);
|
2021-12-28 16:06:23 +08:00
|
|
|
auto motion = MoveBy::create(2, Vec2(100, 0));
|
|
|
|
_root->runAction(RepeatForever::create(Sequence::create(motion, motion->reverse(), nullptr)));
|
|
|
|
_root->runAction(action1);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
auto colorAction = RepeatForever::create(Sequence::create(
|
2021-12-28 16:06:23 +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), nullptr));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
_streak->runAction(colorAction);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MotionStreakTest1::onUpdate(float delta)
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
_streak->setPosition(_target->convertToWorldSpace(Vec2::ZERO));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string MotionStreakTest1::title() const
|
|
|
|
{
|
|
|
|
return "MotionStreak test 1";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// MotionStreakTest2
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
void MotionStreakTest2::onEnter()
|
|
|
|
{
|
|
|
|
MotionStreakTest::onEnter();
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
2019-11-23 20:27:39 +08:00
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(MotionStreakTest2::onTouchesMoved, this);
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// create the streak object and add it to the scene
|
2021-12-28 16:06:23 +08:00
|
|
|
_streak = MotionStreak::create(3, 3, 64, Color3B::WHITE, s_streak);
|
2019-11-23 20:27:39 +08:00
|
|
|
addChild(_streak);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
_streak->setPosition(Vec2(s.width / 2, s.height / 2));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MotionStreakTest2::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
|
|
|
|
{
|
|
|
|
auto touchLocation = touches[0]->getLocation();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
_streak->setPosition(touchLocation);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string MotionStreakTest2::title() const
|
|
|
|
{
|
|
|
|
return "MotionStreak test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string MotionStreakTest2::subtitle() const
|
|
|
|
{
|
|
|
|
return "Need Touch Movement";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Issue1358
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
void Issue1358::onEnter()
|
|
|
|
{
|
|
|
|
MotionStreakTest::onEnter();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// ask director the the window size
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
_streak = MotionStreak::create(2.0f, 1.0f, 50.0f, Color3B(255, 255, 0), "Images/Icon.png");
|
|
|
|
addChild(_streak);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
_center = Vec2(size.width / 2, size.height / 2);
|
|
|
|
_radius = size.width / 3;
|
|
|
|
_angle = 0.0f;
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
schedule(CC_SCHEDULE_SELECTOR(Issue1358::update), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Issue1358::update(float dt)
|
|
|
|
{
|
|
|
|
_angle += 1.0f;
|
2021-12-28 16:06:23 +08:00
|
|
|
_streak->setPosition(
|
|
|
|
Vec2(_center.x + cosf(_angle / 180 * M_PI) * _radius, _center.y + sinf(_angle / 180 * M_PI) * _radius));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Issue1358::title() const
|
|
|
|
{
|
|
|
|
return "Issue 1358";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Issue1358::subtitle() const
|
|
|
|
{
|
|
|
|
return "The tail should use the texture";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Issue12226
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
void Issue12226::onEnter()
|
|
|
|
{
|
|
|
|
MotionStreakTest::onEnter();
|
|
|
|
|
|
|
|
// ask director the the window size
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto radius = size.width / 3;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
auto outer = Sprite::create("Images/grossini.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
outer->setPosition(size / 2);
|
2019-11-23 20:27:39 +08:00
|
|
|
addChild(outer);
|
|
|
|
|
|
|
|
_streak = MotionStreak::create(1.0f, 3, radius * 1.5f, Color3B(0xA0, 0xA0, 0xA0), "ccb/particle-smoke.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
// motionStreak->setOpacity(0x70);
|
2019-11-23 20:27:39 +08:00
|
|
|
_streak->setPosition(outer->getPosition());
|
|
|
|
|
|
|
|
this->addChild(_streak, outer->getLocalZOrder() - 1);
|
|
|
|
|
|
|
|
outer->setUserData(_streak);
|
|
|
|
|
|
|
|
const uint32_t length = (radius * 0.95);
|
|
|
|
|
|
|
|
std::function<void(float)> updateMotionStreak = [=](float dt) {
|
2021-12-28 16:06:23 +08:00
|
|
|
Vec2 position =
|
|
|
|
Vec2(outer->getPositionX() + length * cosf(-1 * CC_DEGREES_TO_RADIANS(outer->getRotation() + 90.0f)),
|
|
|
|
outer->getPositionY() + length * sinf(-1 * CC_DEGREES_TO_RADIANS(outer->getRotation() + 90.0f)));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
_streak->setPosition(position);
|
|
|
|
};
|
|
|
|
|
|
|
|
outer->schedule(updateMotionStreak, 1 / 240.0f, CC_REPEAT_FOREVER, 0, "motion1scheduler");
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto rot = RotateBy::create(2, 360);
|
2019-11-23 20:27:39 +08:00
|
|
|
auto forever = RepeatForever::create(rot);
|
|
|
|
outer->runAction(forever);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Issue12226::title() const
|
|
|
|
{
|
|
|
|
return "Github Issue 12226";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Issue12226::subtitle() const
|
|
|
|
{
|
|
|
|
return "Image should look without artifacts";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// MotionStreakTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
MotionStreakTest::MotionStreakTest() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
MotionStreakTest::~MotionStreakTest() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
std::string MotionStreakTest::title() const
|
|
|
|
{
|
|
|
|
return "No title";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string MotionStreakTest::subtitle() const
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void MotionStreakTest::onEnter()
|
|
|
|
{
|
|
|
|
TestCase::onEnter();
|
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto itemMode = MenuItemToggle::createWithCallback(CC_CALLBACK_1(MotionStreakTest::modeCallback, this),
|
|
|
|
MenuItemFont::create("Use High Quality Mode"),
|
|
|
|
MenuItemFont::create("Use Fast Mode"), nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
auto menuMode = Menu::create(itemMode, nullptr);
|
|
|
|
addChild(menuMode);
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
menuMode->setPosition(Vec2(s.width / 2, s.height / 4));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void MotionStreakTest::modeCallback(Ref* pSender)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
bool fastMode = _streak->isFastMode();
|
2021-12-28 16:06:23 +08:00
|
|
|
_streak->setFastMode(!fastMode);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|