2011-03-22 14:59:10 +08:00
|
|
|
#include "ZwoptexTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
#define MAX_LAYER 1
|
2011-03-22 14:59:10 +08:00
|
|
|
|
|
|
|
static int sceneIdx = -1;
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* nextZwoptexTest();
|
|
|
|
Layer* backZwoptexTest();
|
|
|
|
Layer* restartZwoptexTest();
|
2011-07-08 15:57:46 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* createZwoptexLayer(int nIndex)
|
2011-03-22 14:59:10 +08:00
|
|
|
{
|
|
|
|
switch(nIndex)
|
|
|
|
{
|
|
|
|
case 0: return new ZwoptexGenericTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* nextZwoptexTest()
|
2011-03-22 14:59:10 +08:00
|
|
|
{
|
|
|
|
sceneIdx++;
|
|
|
|
sceneIdx = sceneIdx % MAX_LAYER;
|
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
Layer* layer = createZwoptexLayer(sceneIdx);
|
|
|
|
layer->autorelease();
|
2011-03-22 14:59:10 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* backZwoptexTest()
|
2011-03-22 14:59:10 +08:00
|
|
|
{
|
|
|
|
sceneIdx--;
|
|
|
|
int total = MAX_LAYER;
|
|
|
|
if( sceneIdx < 0 )
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx += total;
|
2011-03-22 14:59:10 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
Layer* layer = createZwoptexLayer(sceneIdx);
|
|
|
|
layer->autorelease();
|
2011-03-22 14:59:10 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* restartZwoptexTest()
|
2011-03-22 14:59:10 +08:00
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
Layer* layer = createZwoptexLayer(sceneIdx);
|
|
|
|
layer->autorelease();
|
2011-03-22 14:59:10 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ZwoptexTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ZwoptexTest::onEnter()
|
|
|
|
{
|
2013-06-12 07:30:05 +08:00
|
|
|
BaseTest::onEnter();
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void ZwoptexTest::restartCallback(Object* sender)
|
2011-03-22 14:59:10 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene *s = ZwoptexTestScene::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild(restartZwoptexTest());
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void ZwoptexTest::nextCallback(Object* sender)
|
2011-03-22 14:59:10 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene *s = ZwoptexTestScene::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild(nextZwoptexTest());
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void ZwoptexTest::backCallback(Object* sender)
|
2011-03-22 14:59:10 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene *s = ZwoptexTestScene::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild(backZwoptexTest());
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string ZwoptexTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "No title";
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string ZwoptexTest::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "";
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ZwoptexGenericTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ZwoptexGenericTest::onEnter()
|
|
|
|
{
|
|
|
|
ZwoptexTest::onEnter();
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Size 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");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
LayerColor *layer1 = LayerColor::create(Color4B(255, 0, 0, 255), 85, 121);
|
2013-07-12 14:11:55 +08:00
|
|
|
layer1->setPosition(Point(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
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
sprite1 = Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini_dance_01.png"));
|
2013-07-12 14:11:55 +08:00
|
|
|
sprite1->setPosition(Point( 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
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
sprite1->setFlipX(false);
|
|
|
|
sprite1->setFlipY(false);
|
2011-03-22 14:59:10 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
LayerColor *layer2 = LayerColor::create(Color4B(255, 0, 0, 255), 85, 121);
|
2013-07-12 14:11:55 +08:00
|
|
|
layer2->setPosition(Point(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);
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
sprite2 = Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini_dance_generic_01.png"));
|
2013-07-12 14:11:55 +08:00
|
|
|
sprite2->setPosition(Point( 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
|
|
|
|
|
|
|
sprite2->setFlipX(false);
|
|
|
|
sprite2->setFlipY(false);
|
|
|
|
|
|
|
|
schedule(schedule_selector(ZwoptexGenericTest::startIn05Secs), 1.0f);
|
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
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
unschedule(schedule_selector(ZwoptexGenericTest::startIn05Secs));
|
|
|
|
schedule(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;
|
|
|
|
int i = counter % 4;
|
2011-03-22 14:59:10 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
switch ( i )
|
2011-03-22 14:59:10 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprite1->setFlipX(fx);
|
2011-03-22 14:59:10 +08:00
|
|
|
sprite2->setFlipX(fx);
|
|
|
|
sprite1->setFlipY(fy);
|
|
|
|
sprite2->setFlipY(fy);
|
|
|
|
|
2012-04-19 14:35:52 +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);
|
2013-07-18 07:56:19 +08:00
|
|
|
sprite1->setDisplayFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str1));
|
|
|
|
sprite2->setDisplayFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str2));
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ZwoptexGenericTest::~ZwoptexGenericTest()
|
|
|
|
{
|
|
|
|
sprite1->release();
|
|
|
|
sprite2->release();
|
2013-07-12 06:24:23 +08:00
|
|
|
SpriteFrameCache *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
|
|
|
}
|
|
|
|
|
|
|
|
std::string ZwoptexGenericTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Zwoptex Tests";
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string ZwoptexGenericTest::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Coordinate Formats, Rotation, Trimming, flipX/Y";
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ZwoptexTestScene::runThisTest()
|
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
Layer* layer = nextZwoptexTest();
|
|
|
|
addChild(layer);
|
2011-03-22 14:59:10 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2011-03-22 14:59:10 +08:00
|
|
|
}
|