2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +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
|
|
|
|
2018-01-29 16:25:32 +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
|
|
|
|
2018-01-29 16:25:32 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-04-08 14:16:29 +08:00
|
|
|
#include "MotionStreakTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2015-04-09 08:37:30 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
kTagLabel = 1,
|
|
|
|
kTagSprite1 = 2,
|
|
|
|
kTagSprite2 = 3,
|
2012-06-12 16:56:34 +08:00
|
|
|
};
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
MotionStreakTests::MotionStreakTests()
|
2013-07-23 08:25:44 +08:00
|
|
|
{
|
2015-04-03 14:31:03 +08:00
|
|
|
ADD_TEST_CASE(MotionStreakTest1);
|
|
|
|
ADD_TEST_CASE(MotionStreakTest2);
|
|
|
|
ADD_TEST_CASE(Issue1358);
|
2016-07-07 07:37:15 +08:00
|
|
|
ADD_TEST_CASE(Issue12226);
|
2013-07-23 08:25:44 +08:00
|
|
|
}
|
|
|
|
|
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();
|
2021-12-28 16:06:23 +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);
|
2021-12-28 16:06:23 +08:00
|
|
|
_root->setPosition(Vec2(s.width / 2, s.height / 2));
|
|
|
|
|
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);
|
2021-12-28 16:06:23 +08:00
|
|
|
_target->setPosition(Vec2(s.width / 4, 0.0f));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// create the streak object and add it to the scene
|
2016-07-07 07:37:15 +08:00
|
|
|
_streak = MotionStreak::create(2, 3, 32, Color3B::GREEN, s_streak);
|
|
|
|
addChild(_streak);
|
2017-02-24 12:45:41 +08:00
|
|
|
// schedule an update on each frame so we can synchronize the streak with the target
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(MotionStreakTest1::onUpdate));
|
2021-12-28 16:06:23 +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);
|
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);
|
2012-03-22 14:32:32 +08:00
|
|
|
|
2013-08-16 16:05:27 +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));
|
2012-03-22 14:32:32 +08:00
|
|
|
|
2016-07-07 07:37:15 +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
|
|
|
{
|
2021-12-28 16:06:23 +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
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
2022-07-15 19:17:01 +08:00
|
|
|
listener->onTouchesMoved = AX_CALLBACK_2(MotionStreakTest2::onTouchesMoved, this);
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +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);
|
2016-07-07 07:37:15 +08:00
|
|
|
addChild(_streak);
|
2021-12-28 16:06:23 +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();
|
2021-12-28 16:06:23 +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
|
|
|
}
|
|
|
|
|
2019-05-22 09:52:40 +08:00
|
|
|
std::string MotionStreakTest2::subtitle() const
|
|
|
|
{
|
|
|
|
return "Need Touch Movement";
|
|
|
|
}
|
|
|
|
|
2012-06-12 16:56:34 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Issue1358
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
void Issue1358::onEnter()
|
|
|
|
{
|
|
|
|
MotionStreakTest::onEnter();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2012-06-12 16:56:34 +08:00
|
|
|
// ask director the the window size
|
2013-08-16 16:05:27 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2016-07-07 07:37:15 +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;
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(Issue1358::update), 0);
|
2012-06-12 16:56:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Issue1358::update(float dt)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_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));
|
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";
|
|
|
|
}
|
|
|
|
|
2016-07-07 07:37:15 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// 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;
|
2016-07-07 07:37:15 +08:00
|
|
|
|
|
|
|
auto outer = Sprite::create("Images/grossini.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
outer->setPosition(size / 2);
|
2016-07-07 07:37:15 +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);
|
2016-07-07 07:37:15 +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 =
|
2022-07-15 19:17:01 +08:00
|
|
|
Vec2(outer->getPositionX() + length * cosf(-1 * AX_DEGREES_TO_RADIANS(outer->getRotation() + 90.0f)),
|
|
|
|
outer->getPositionY() + length * sinf(-1 * AX_DEGREES_TO_RADIANS(outer->getRotation() + 90.0f)));
|
2016-07-07 07:37:15 +08:00
|
|
|
|
|
|
|
_streak->setPosition(position);
|
|
|
|
};
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
outer->schedule(updateMotionStreak, 1 / 240.0f, AX_REPEAT_FOREVER, 0, "motion1scheduler");
|
2016-07-07 07:37:15 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto rot = RotateBy::create(2, 360);
|
2016-07-07 07:37:15 +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";
|
|
|
|
}
|
|
|
|
|
2010-08-25 17:02:58 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// MotionStreakTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
MotionStreakTest::MotionStreakTest() {}
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
MotionStreakTest::~MotionStreakTest() {}
|
2012-04-08 14:16:29 +08:00
|
|
|
|
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()
|
|
|
|
{
|
2015-04-03 14:31:03 +08:00
|
|
|
TestCase::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
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
auto itemMode = MenuItemToggle::createWithCallback(AX_CALLBACK_1(MotionStreakTest::modeCallback, this),
|
2021-12-28 16:06:23 +08:00
|
|
|
MenuItemFont::create("Use High Quality Mode"),
|
|
|
|
MenuItemFont::create("Use Fast Mode"), 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
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
menuMode->setPosition(Vec2(s.width / 2, s.height / 4));
|
2012-03-22 14:32:32 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void MotionStreakTest::modeCallback(Ref* pSender)
|
2012-03-22 14:32:32 +08:00
|
|
|
{
|
2016-07-07 07:37:15 +08:00
|
|
|
bool fastMode = _streak->isFastMode();
|
2021-12-28 16:06:23 +08:00
|
|
|
_streak->setFastMode(!fastMode);
|
2010-08-25 17:02:58 +08:00
|
|
|
}
|