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-07-09 22:23:34 +08:00
|
|
|
https://axis-project.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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-03-22 14:59:10 +08:00
|
|
|
#include "ZwoptexTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2015-04-09 08:37:30 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
ZwoptexTests::ZwoptexTests()
|
2011-03-22 14:59:10 +08:00
|
|
|
{
|
2015-04-03 14:31:03 +08:00
|
|
|
ADD_TEST_CASE(ZwoptexGenericTest);
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ZwoptexGenericTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ZwoptexGenericTest::onEnter()
|
|
|
|
{
|
|
|
|
ZwoptexTest::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2011-03-22 14:59:10 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("zwoptex/grossini.plist");
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("zwoptex/grossini-generic.plist");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer1 = LayerColor::create(Color4B(255, 0, 0, 255), 85, 121);
|
2021-12-28 16:06:23 +08:00
|
|
|
layer1->setPosition(Vec2(s.width / 2 - 80 - (85.0f * 0.5f), s.height / 2 - (121.0f * 0.5f)));
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(layer1);
|
2011-03-22 14:59:10 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
sprite1 =
|
|
|
|
Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini_dance_01.png"));
|
|
|
|
sprite1->setPosition(Vec2(s.width / 2 - 80, s.height / 2));
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(sprite1);
|
2011-03-22 14:59:10 +08:00
|
|
|
|
2013-09-16 20:38:03 +08:00
|
|
|
sprite1->setFlippedX(false);
|
|
|
|
sprite1->setFlippedY(false);
|
2011-03-22 14:59:10 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer2 = LayerColor::create(Color4B(255, 0, 0, 255), 85, 121);
|
2021-12-28 16:06:23 +08:00
|
|
|
layer2->setPosition(Vec2(s.width / 2 + 80 - (85.0f * 0.5f), s.height / 2 - (121.0f * 0.5f)));
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(layer2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
sprite2 = Sprite::createWithSpriteFrame(
|
|
|
|
SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini_dance_generic_01.png"));
|
|
|
|
sprite2->setPosition(Vec2(s.width / 2 + 80, s.height / 2));
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(sprite2);
|
2011-03-22 14:59:10 +08:00
|
|
|
|
2013-09-16 20:38:03 +08:00
|
|
|
sprite2->setFlippedX(false);
|
|
|
|
sprite2->setFlippedY(false);
|
2011-03-22 14:59:10 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(ZwoptexGenericTest::startIn05Secs), 1.0f);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
sprite1->retain();
|
|
|
|
sprite2->retain();
|
2011-03-22 14:59:10 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
counter = 0;
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void ZwoptexGenericTest::startIn05Secs(float dt)
|
2011-03-22 14:59:10 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
unschedule(AX_SCHEDULE_SELECTOR(ZwoptexGenericTest::startIn05Secs));
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(ZwoptexGenericTest::flipSprites), 0.5f);
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int spriteFrameIndex = 0;
|
2012-06-08 13:55:28 +08:00
|
|
|
void ZwoptexGenericTest::flipSprites(float dt)
|
2011-03-22 14:59:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
counter++;
|
2011-03-22 14:59:10 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
bool fx = false;
|
|
|
|
bool fy = false;
|
2021-12-28 16:06:23 +08:00
|
|
|
int i = counter % 4;
|
2011-03-22 14:59:10 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
switch (i)
|
2011-03-22 14:59:10 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
case 0:
|
|
|
|
fx = false;
|
|
|
|
fy = false;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
fx = true;
|
|
|
|
fy = false;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
fx = false;
|
|
|
|
fy = true;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
fx = true;
|
|
|
|
fy = true;
|
|
|
|
break;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-09-16 20:38:03 +08:00
|
|
|
sprite1->setFlippedX(fx);
|
|
|
|
sprite2->setFlippedX(fx);
|
|
|
|
sprite1->setFlippedY(fy);
|
|
|
|
sprite2->setFlippedY(fy);
|
2011-03-22 14:59:10 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
if (++spriteFrameIndex > 14)
|
2011-03-22 14:59:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
spriteFrameIndex = 1;
|
|
|
|
}
|
2011-03-22 14:59:10 +08:00
|
|
|
|
|
|
|
char str1[32] = {0};
|
|
|
|
char str2[32] = {0};
|
|
|
|
sprintf(str1, "grossini_dance_%02d.png", spriteFrameIndex);
|
|
|
|
sprintf(str2, "grossini_dance_generic_%02d.png", spriteFrameIndex);
|
2014-03-24 10:12:40 +08:00
|
|
|
sprite1->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str1));
|
|
|
|
sprite2->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str2));
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ZwoptexGenericTest::~ZwoptexGenericTest()
|
|
|
|
{
|
|
|
|
sprite1->release();
|
|
|
|
sprite2->release();
|
2013-08-16 16:05:27 +08:00
|
|
|
auto cache = SpriteFrameCache::getInstance();
|
2011-12-01 14:15:10 +08:00
|
|
|
cache->removeSpriteFramesFromFile("zwoptex/grossini.plist");
|
|
|
|
cache->removeSpriteFramesFromFile("zwoptex/grossini-generic.plist");
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ZwoptexGenericTest::title() const
|
2011-03-22 14:59:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Zwoptex Tests";
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ZwoptexGenericTest::subtitle() const
|
2011-03-22 14:59:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Coordinate Formats, Rotation, Trimming, flipX/Y";
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|