mirror of https://github.com/axmolengine/axmol.git
Merge pull request #16057 from ricardoquesada/issue_12226
test: add test case for Github issue #12226
This commit is contained in:
commit
891fe706da
|
@ -47,24 +47,24 @@ class CC_DLL MotionStreak : public Node, public TextureProtocol
|
|||
public:
|
||||
/** Creates and initializes a motion streak with fade in seconds, minimum segments, stroke's width, color, texture filename.
|
||||
*
|
||||
* @param fade The fade time, in seconds.
|
||||
* @param timeToFade The fade time, in seconds.
|
||||
* @param minSeg The minimum segments.
|
||||
* @param stroke The width of stroke.
|
||||
* @param color The color of stroke.
|
||||
* @param path The texture file name of stoke.
|
||||
* @param strokeWidth The width of stroke.
|
||||
* @param strokeColor The color of stroke.
|
||||
* @param iamgePath The texture file name of stoke.
|
||||
* @return An autoreleased MotionStreak object.
|
||||
*/
|
||||
static MotionStreak* create(float fade, float minSeg, float stroke, const Color3B& color, const std::string& path);
|
||||
static MotionStreak* create(float timeToFade, float minSeg, float strokeWidth, const Color3B& strokeColor, const std::string& iamgePath);
|
||||
/** Creates and initializes a motion streak with fade in seconds, minimum segments, stroke's width, color, texture.
|
||||
*
|
||||
* @param fade The fade time, in seconds.
|
||||
* @param timeToFade The fade time, in seconds.
|
||||
* @param minSeg The minimum segments.
|
||||
* @param stroke The width of stroke.
|
||||
* @param color The color of stroke.
|
||||
* @param strokeWidth The width of stroke.
|
||||
* @param strokeColor The color of stroke.
|
||||
* @param texture The texture name of stoke.
|
||||
* @return An autoreleased MotionStreak object.
|
||||
*/
|
||||
static MotionStreak* create(float fade, float minSeg, float stroke, const Color3B& color, Texture2D* texture);
|
||||
static MotionStreak* create(float timeToFade, float minSeg, float strokeWidth, const Color3B& strokeColor, Texture2D* texture);
|
||||
|
||||
/** Color used for the tint.
|
||||
*
|
||||
|
|
|
@ -14,6 +14,7 @@ MotionStreakTests::MotionStreakTests()
|
|||
ADD_TEST_CASE(MotionStreakTest1);
|
||||
ADD_TEST_CASE(MotionStreakTest2);
|
||||
ADD_TEST_CASE(Issue1358);
|
||||
ADD_TEST_CASE(Issue12226);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
@ -39,8 +40,8 @@ void MotionStreakTest1::onEnter()
|
|||
_target->setPosition(Vec2(s.width/4, 0));
|
||||
|
||||
// create the streak object and add it to the scene
|
||||
streak = MotionStreak::create(2, 3, 32, Color3B::GREEN, s_streak);
|
||||
addChild(streak);
|
||||
_streak = MotionStreak::create(2, 3, 32, Color3B::GREEN, s_streak);
|
||||
addChild(_streak);
|
||||
// schedule an update on each frame so we can syncronize the streak with the target
|
||||
schedule(CC_SCHEDULE_SELECTOR(MotionStreakTest1::onUpdate));
|
||||
|
||||
|
@ -61,12 +62,12 @@ void MotionStreakTest1::onEnter()
|
|||
TintTo::create(0.2f, 255, 255, 255),
|
||||
nullptr));
|
||||
|
||||
streak->runAction(colorAction);
|
||||
_streak->runAction(colorAction);
|
||||
}
|
||||
|
||||
void MotionStreakTest1::onUpdate(float delta)
|
||||
{
|
||||
streak->setPosition( _target->convertToWorldSpace(Vec2::ZERO) );
|
||||
_streak->setPosition( _target->convertToWorldSpace(Vec2::ZERO) );
|
||||
}
|
||||
|
||||
std::string MotionStreakTest1::title() const
|
||||
|
@ -91,17 +92,17 @@ void MotionStreakTest2::onEnter()
|
|||
auto s = Director::getInstance()->getWinSize();
|
||||
|
||||
// create the streak object and add it to the scene
|
||||
streak = MotionStreak::create(3, 3, 64, Color3B::WHITE, s_streak );
|
||||
addChild(streak);
|
||||
_streak = MotionStreak::create(3, 3, 64, Color3B::WHITE, s_streak );
|
||||
addChild(_streak);
|
||||
|
||||
streak->setPosition( Vec2(s.width/2, s.height/2) );
|
||||
_streak->setPosition( Vec2(s.width/2, s.height/2) );
|
||||
}
|
||||
|
||||
void MotionStreakTest2::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
|
||||
{
|
||||
auto touchLocation = touches[0]->getLocation();
|
||||
|
||||
streak->setPosition( touchLocation );
|
||||
_streak->setPosition( touchLocation );
|
||||
}
|
||||
|
||||
std::string MotionStreakTest2::title() const
|
||||
|
@ -122,8 +123,8 @@ void Issue1358::onEnter()
|
|||
// ask director the the window size
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
|
||||
streak = MotionStreak::create(2.0f, 1.0f, 50.0f, Color3B(255, 255, 0), "Images/Icon.png");
|
||||
addChild(streak);
|
||||
_streak = MotionStreak::create(2.0f, 1.0f, 50.0f, Color3B(255, 255, 0), "Images/Icon.png");
|
||||
addChild(_streak);
|
||||
|
||||
|
||||
_center = Vec2(size.width/2, size.height/2);
|
||||
|
@ -136,7 +137,7 @@ void Issue1358::onEnter()
|
|||
void Issue1358::update(float dt)
|
||||
{
|
||||
_angle += 1.0f;
|
||||
streak->setPosition(Vec2(_center.x + cosf(_angle/180 * M_PI)*_radius,
|
||||
_streak->setPosition(Vec2(_center.x + cosf(_angle/180 * M_PI)*_radius,
|
||||
_center.y + sinf(_angle/ 180 * M_PI)*_radius));
|
||||
}
|
||||
|
||||
|
@ -150,6 +151,62 @@ 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();
|
||||
|
||||
auto radius = size.width/3;
|
||||
|
||||
auto outer = Sprite::create("Images/grossini.png");
|
||||
outer->setPosition(size/2);
|
||||
addChild(outer);
|
||||
|
||||
|
||||
_streak = MotionStreak::create(1.0f, 3, radius * 1.5f, Color3B(0xA0, 0xA0, 0xA0), "ccb/particle-smoke.png");
|
||||
// motionStreak->setOpacity(0x70);
|
||||
_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) {
|
||||
|
||||
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)));
|
||||
|
||||
_streak->setPosition(position);
|
||||
};
|
||||
|
||||
outer->schedule(updateMotionStreak, 1 / 240.0f, CC_REPEAT_FOREVER, 0, "motion1scheduler");
|
||||
|
||||
auto rot = RotateBy::create(2, 360);
|
||||
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
|
||||
|
@ -193,6 +250,6 @@ void MotionStreakTest::onEnter()
|
|||
|
||||
void MotionStreakTest::modeCallback(Ref *pSender)
|
||||
{
|
||||
bool fastMode = streak->isFastMode();
|
||||
streak->setFastMode(! fastMode);
|
||||
bool fastMode = _streak->isFastMode();
|
||||
_streak->setFastMode(! fastMode);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
|
||||
void modeCallback(cocos2d::Ref* sender);
|
||||
protected:
|
||||
cocos2d::MotionStreak* streak;
|
||||
cocos2d::MotionStreak* _streak;
|
||||
};
|
||||
|
||||
class MotionStreakTest1 : public MotionStreakTest
|
||||
|
@ -62,4 +62,15 @@ private:
|
|||
float _angle;
|
||||
};
|
||||
|
||||
class Issue12226 : public MotionStreakTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Issue12226);
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void onEnter() override;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue