mirror of https://github.com/axmolengine/axmol.git
Make all test cases work fine with new test framework.
This commit is contained in:
parent
6f47006324
commit
0d51c13743
|
@ -9,61 +9,16 @@ enum
|
|||
kTagSequence,
|
||||
};
|
||||
|
||||
Layer* nextActionManagerAction();
|
||||
Layer* backActionManagerAction();
|
||||
Layer* restartActionManagerAction();
|
||||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
#define MAX_LAYER 6
|
||||
|
||||
Layer* createActionManagerLayer(int nIndex)
|
||||
ActionManagerTests::ActionManagerTests()
|
||||
{
|
||||
switch(nIndex)
|
||||
{
|
||||
case 0: return new CrashTest();
|
||||
case 1: return new LogicTest();
|
||||
case 2: return new PauseTest();
|
||||
case 3: return new StopActionTest();
|
||||
case 4: return new StopAllActionsTest();
|
||||
case 5: return new ResumeTest();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
ADD_TEST_CASE(CrashTest);
|
||||
ADD_TEST_CASE(LogicTest);
|
||||
ADD_TEST_CASE(PauseTest);
|
||||
ADD_TEST_CASE(StopActionTest);
|
||||
ADD_TEST_CASE(StopAllActionsTest);
|
||||
ADD_TEST_CASE(ResumeTest);
|
||||
}
|
||||
|
||||
Layer* nextActionManagerAction()
|
||||
{
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_LAYER;
|
||||
|
||||
auto layer = createActionManagerLayer(sceneIdx);
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
Layer* backActionManagerAction()
|
||||
{
|
||||
sceneIdx--;
|
||||
int total = MAX_LAYER;
|
||||
if( sceneIdx < 0 )
|
||||
sceneIdx += total;
|
||||
|
||||
auto layer = createActionManagerLayer(sceneIdx);
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
Layer* restartActionManagerAction()
|
||||
{
|
||||
auto layer = createActionManagerLayer(sceneIdx);
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// ActionManagerTest
|
||||
|
@ -86,30 +41,6 @@ std::string ActionManagerTest::subtitle() const
|
|||
{
|
||||
return "No title";
|
||||
}
|
||||
void ActionManagerTest::restartCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ActionManagerTestScene();
|
||||
s->addChild(restartActionManagerAction());
|
||||
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void ActionManagerTest::nextCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ActionManagerTestScene();
|
||||
s->addChild( nextActionManagerAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void ActionManagerTest::backCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ActionManagerTestScene();
|
||||
s->addChild( backActionManagerAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
|
@ -123,7 +54,7 @@ void CrashTest::onEnter()
|
|||
|
||||
auto child = Sprite::create(s_pathGrossini);
|
||||
child->setPosition( VisibleRect::center() );
|
||||
addChild(child, 1);
|
||||
addChild(child, 1, kTagGrossini);
|
||||
|
||||
//Sum of all action's duration is 1.5 second.
|
||||
child->runAction(RotateBy::create(1.5f, 90));
|
||||
|
@ -134,7 +65,7 @@ void CrashTest::onEnter()
|
|||
);
|
||||
|
||||
//After 1.5 second, self will be removed.
|
||||
runAction( Sequence::create(
|
||||
child->runAction(Sequence::create(
|
||||
DelayTime::create(1.4f),
|
||||
CallFunc::create( CC_CALLBACK_0(CrashTest::removeThis,this)),
|
||||
nullptr)
|
||||
|
@ -143,9 +74,10 @@ void CrashTest::onEnter()
|
|||
|
||||
void CrashTest::removeThis()
|
||||
{
|
||||
_parent->removeChild(this, true);
|
||||
auto child = getChildByTag(kTagGrossini);
|
||||
child->removeChild(child, true);
|
||||
|
||||
nextCallback(this);
|
||||
getTestSuite()->enterNextTest();
|
||||
}
|
||||
|
||||
std::string CrashTest::subtitle() const
|
||||
|
@ -357,16 +289,3 @@ void ResumeTest::resumeGrossini(float time)
|
|||
auto director = Director::getInstance();
|
||||
director->getActionManager()->resumeTarget(pGrossini);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// ActionManagerTestScene
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
void ActionManagerTestScene::runThisTest()
|
||||
{
|
||||
auto layer = nextActionManagerAction();
|
||||
addChild(layer);
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
|
||||
class ActionManagerTest: public BaseTest
|
||||
DEFINE_TEST_SUITE(ActionManagerTests);
|
||||
|
||||
class ActionManagerTest : public TestCase
|
||||
{
|
||||
protected:
|
||||
TextureAtlas* _atlas;
|
||||
|
@ -12,19 +14,18 @@ protected:
|
|||
std::string _title;
|
||||
|
||||
public:
|
||||
ActionManagerTest(void);
|
||||
~ActionManagerTest(void);
|
||||
ActionManagerTest();
|
||||
~ActionManagerTest();
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
void restartCallback(Ref* sender) override;
|
||||
void nextCallback(Ref* sender) override;
|
||||
void backCallback(Ref* sender) override;
|
||||
};
|
||||
|
||||
class CrashTest : public ActionManagerTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(CrashTest);
|
||||
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void onEnter() override;
|
||||
void removeThis();
|
||||
|
@ -33,6 +34,8 @@ public:
|
|||
class LogicTest : public ActionManagerTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(LogicTest);
|
||||
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void onEnter() override;
|
||||
void bugMe(Node* node);
|
||||
|
@ -41,6 +44,8 @@ public:
|
|||
class PauseTest : public ActionManagerTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(PauseTest);
|
||||
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void onEnter() override;
|
||||
void unpause(float dt);
|
||||
|
@ -49,6 +54,8 @@ public:
|
|||
class StopActionTest : public ActionManagerTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(StopActionTest);
|
||||
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void onEnter() override;
|
||||
void stopAction();
|
||||
|
@ -57,6 +64,8 @@ public:
|
|||
class StopAllActionsTest : public ActionManagerTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(StopAllActionsTest);
|
||||
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void onEnter() override;
|
||||
void stopAction(float time);
|
||||
|
@ -65,15 +74,11 @@ public:
|
|||
class ResumeTest : public ActionManagerTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(ResumeTest);
|
||||
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void onEnter() override;
|
||||
void resumeGrossini(float time);
|
||||
};
|
||||
|
||||
class ActionManagerTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -32,9 +32,6 @@ enum {
|
|||
kTagSlider = 1,
|
||||
};
|
||||
|
||||
Layer* nextEaseAction();
|
||||
Layer* backEaseAction();
|
||||
Layer* restartEaseAction();
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
|
@ -975,84 +972,34 @@ std::string SpeedTest::subtitle() const
|
|||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
enum
|
||||
ActionsEaseTests::ActionsEaseTests()
|
||||
{
|
||||
IDC_NEXT = 100,
|
||||
IDC_BACK,
|
||||
IDC_RESTART
|
||||
};
|
||||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
#define MAX_LAYER 24
|
||||
|
||||
Layer* createEaseLayer(int nIndex)
|
||||
{
|
||||
switch(nIndex)
|
||||
{
|
||||
case 0: return new SpriteEase();
|
||||
case 1: return new SpriteEaseInOut();
|
||||
case 2: return new SpriteEaseExponential();
|
||||
case 3: return new SpriteEaseExponentialInOut();
|
||||
case 4: return new SpriteEaseSine();
|
||||
case 5: return new SpriteEaseSineInOut();
|
||||
case 6: return new SpriteEaseElastic();
|
||||
case 7: return new SpriteEaseElasticInOut();
|
||||
case 8: return new SpriteEaseBounce();
|
||||
case 9: return new SpriteEaseBounceInOut();
|
||||
case 10: return new SpriteEaseBack();
|
||||
case 11: return new SpriteEaseBackInOut();
|
||||
case 12: return new SpriteEaseBezier();
|
||||
case 13: return new SpriteEaseQuadratic();
|
||||
case 14: return new SpriteEaseQuadraticInOut();
|
||||
case 15: return new SpriteEaseQuartic();
|
||||
case 16: return new SpriteEaseQuarticInOut();
|
||||
case 17: return new SpriteEaseQuintic();
|
||||
case 18: return new SpriteEaseQuinticInOut();
|
||||
case 19: return new SpriteEaseCircle();
|
||||
case 20: return new SpriteEaseCircleInOut();
|
||||
case 21: return new SpriteEaseCubic();
|
||||
case 22: return new SpriteEaseCubicInOut();
|
||||
case MAX_LAYER-1: return new SpeedTest();
|
||||
}
|
||||
|
||||
|
||||
return nullptr;
|
||||
ADD_TEST_CASE(SpriteEase);
|
||||
ADD_TEST_CASE(SpriteEaseInOut);
|
||||
ADD_TEST_CASE(SpriteEaseExponential);
|
||||
ADD_TEST_CASE(SpriteEaseExponentialInOut);
|
||||
ADD_TEST_CASE(SpriteEaseSine);
|
||||
ADD_TEST_CASE(SpriteEaseSineInOut);
|
||||
ADD_TEST_CASE(SpriteEaseElastic);
|
||||
ADD_TEST_CASE(SpriteEaseElasticInOut);
|
||||
ADD_TEST_CASE(SpriteEaseBounce);
|
||||
ADD_TEST_CASE(SpriteEaseBounceInOut);
|
||||
ADD_TEST_CASE(SpriteEaseBack);
|
||||
ADD_TEST_CASE(SpriteEaseBackInOut);
|
||||
ADD_TEST_CASE(SpriteEaseBezier);
|
||||
ADD_TEST_CASE(SpriteEaseQuadratic);
|
||||
ADD_TEST_CASE(SpriteEaseQuadraticInOut);
|
||||
ADD_TEST_CASE(SpriteEaseQuartic);
|
||||
ADD_TEST_CASE(SpriteEaseQuarticInOut);
|
||||
ADD_TEST_CASE(SpriteEaseQuintic);
|
||||
ADD_TEST_CASE(SpriteEaseQuinticInOut);
|
||||
ADD_TEST_CASE(SpriteEaseCircle);
|
||||
ADD_TEST_CASE(SpriteEaseCircleInOut);
|
||||
ADD_TEST_CASE(SpriteEaseCubic);
|
||||
ADD_TEST_CASE(SpriteEaseCubicInOut);
|
||||
ADD_TEST_CASE(SpeedTest);
|
||||
}
|
||||
|
||||
Layer* nextEaseAction()
|
||||
{
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_LAYER;
|
||||
|
||||
auto layer = createEaseLayer(sceneIdx);
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
Layer* backEaseAction()
|
||||
{
|
||||
sceneIdx--;
|
||||
int total = MAX_LAYER;
|
||||
if( sceneIdx < 0 )
|
||||
sceneIdx += total;
|
||||
|
||||
auto layer = createEaseLayer(sceneIdx);
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
Layer* restartEaseAction()
|
||||
{
|
||||
auto layer = createEaseLayer(sceneIdx);
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
|
||||
EaseSpriteDemo::EaseSpriteDemo(void)
|
||||
{
|
||||
}
|
||||
|
@ -1079,7 +1026,7 @@ std::string EaseSpriteDemo::subtitle() const
|
|||
|
||||
void EaseSpriteDemo::onEnter()
|
||||
{
|
||||
BaseTest::onEnter();
|
||||
TestCase::onEnter();
|
||||
|
||||
// Or you can create an sprite using a filename. PNG and BMP files are supported. Probably TIFF too
|
||||
_grossini = Sprite::create(s_pathGrossini); _grossini->retain();
|
||||
|
@ -1094,36 +1041,3 @@ void EaseSpriteDemo::onEnter()
|
|||
_kathia->setPosition(VisibleRect::left().x + 60, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height*2.5f/5);
|
||||
_tamara->setPosition(VisibleRect::left().x + 60, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height*4/5);
|
||||
}
|
||||
|
||||
void EaseSpriteDemo::restartCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ActionsEaseTestScene();//CCScene::create();
|
||||
s->addChild(restartEaseAction());
|
||||
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void EaseSpriteDemo::nextCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ActionsEaseTestScene();//CCScene::create();
|
||||
s->addChild( nextEaseAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void EaseSpriteDemo::backCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ActionsEaseTestScene();//CCScene::create();
|
||||
s->addChild( backEaseAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void ActionsEaseTestScene::runThisTest()
|
||||
{
|
||||
auto layer = nextEaseAction();
|
||||
addChild(layer);
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,9 @@
|
|||
|
||||
USING_NS_CC;
|
||||
|
||||
class EaseSpriteDemo : public BaseTest
|
||||
DEFINE_TEST_SUITE(ActionsEaseTests);
|
||||
|
||||
class EaseSpriteDemo : public TestCase
|
||||
{
|
||||
protected:
|
||||
Sprite* _grossini;
|
||||
|
@ -49,10 +51,6 @@ public:
|
|||
virtual void onEnter() override;
|
||||
|
||||
void centerSprites(unsigned int numberOfSprites);
|
||||
|
||||
void restartCallback(Ref* sender) override;
|
||||
void nextCallback(Ref* sender) override;
|
||||
void backCallback(Ref* sender) override;
|
||||
|
||||
void positionForTwo();
|
||||
};
|
||||
|
@ -60,6 +58,8 @@ public:
|
|||
class SpriteEase : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEase);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
|
@ -69,6 +69,8 @@ public:
|
|||
class SpriteEaseInOut : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseInOut);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -76,6 +78,8 @@ public:
|
|||
class SpriteEaseExponential : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseExponential);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -83,6 +87,8 @@ public:
|
|||
class SpriteEaseExponentialInOut : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseExponentialInOut);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -90,6 +96,8 @@ public:
|
|||
class SpriteEaseSine : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseSine);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -97,6 +105,8 @@ public:
|
|||
class SpriteEaseSineInOut : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseSineInOut);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -104,6 +114,8 @@ public:
|
|||
class SpriteEaseElastic : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseElastic);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -111,6 +123,8 @@ public:
|
|||
class SpriteEaseElasticInOut : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseElasticInOut);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -118,6 +132,8 @@ public:
|
|||
class SpriteEaseBounce : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseBounce);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -125,6 +141,8 @@ public:
|
|||
class SpriteEaseBounceInOut : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseBounceInOut);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -132,6 +150,8 @@ public:
|
|||
class SpriteEaseBack : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseBack);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -139,6 +159,8 @@ public:
|
|||
class SpriteEaseBackInOut : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseBackInOut);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -146,6 +168,8 @@ public:
|
|||
class SpriteEaseBezier : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseBezier);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -153,6 +177,8 @@ public:
|
|||
class SpriteEaseQuadratic : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseQuadratic);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -160,6 +186,8 @@ public:
|
|||
class SpriteEaseQuadraticInOut : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseQuadraticInOut);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -167,6 +195,8 @@ public:
|
|||
class SpriteEaseQuartic : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseQuartic);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -174,6 +204,8 @@ public:
|
|||
class SpriteEaseQuarticInOut : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseQuarticInOut);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -181,6 +213,8 @@ public:
|
|||
class SpriteEaseQuintic : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseQuintic);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -188,6 +222,8 @@ public:
|
|||
class SpriteEaseQuinticInOut : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseQuinticInOut);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -196,6 +232,8 @@ public:
|
|||
class SpriteEaseCircle : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseCircle);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -203,6 +241,8 @@ public:
|
|||
class SpriteEaseCircleInOut : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseCircleInOut);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -210,6 +250,8 @@ public:
|
|||
class SpriteEaseCubic : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseCubic);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -217,23 +259,21 @@ public:
|
|||
class SpriteEaseCubicInOut : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteEaseCubicInOut);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
class SpeedTest : public EaseSpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpeedTest);
|
||||
|
||||
void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void altertime(float dt);
|
||||
};
|
||||
|
||||
class ActionsEaseTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,70 +26,17 @@
|
|||
#include "ActionsProgressTest.h"
|
||||
#include "../testResource.h"
|
||||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
#define MAX_LAYER 7
|
||||
|
||||
Layer* nextAction();
|
||||
Layer* backAction();
|
||||
Layer* restartAction();
|
||||
|
||||
Layer* createLayer(int nIndex)
|
||||
ActionsProgressTests::ActionsProgressTests()
|
||||
{
|
||||
switch(nIndex)
|
||||
{
|
||||
case 0: return new SpriteProgressToRadial();
|
||||
case 1: return new SpriteProgressToHorizontal();
|
||||
case 2: return new SpriteProgressToVertical();
|
||||
case 3: return new SpriteProgressToRadialMidpointChanged();
|
||||
case 4: return new SpriteProgressBarVarious();
|
||||
case 5: return new SpriteProgressBarTintAndFade();
|
||||
case 6: return new SpriteProgressWithSpriteFrame();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
ADD_TEST_CASE(SpriteProgressToRadial);
|
||||
ADD_TEST_CASE(SpriteProgressToHorizontal);
|
||||
ADD_TEST_CASE(SpriteProgressToVertical);
|
||||
ADD_TEST_CASE(SpriteProgressToRadialMidpointChanged);
|
||||
ADD_TEST_CASE(SpriteProgressBarVarious);
|
||||
ADD_TEST_CASE(SpriteProgressBarTintAndFade);
|
||||
ADD_TEST_CASE(SpriteProgressWithSpriteFrame);
|
||||
}
|
||||
|
||||
Layer* nextAction()
|
||||
{
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_LAYER;
|
||||
|
||||
auto layer = createLayer(sceneIdx);
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
Layer* backAction()
|
||||
{
|
||||
sceneIdx--;
|
||||
int total = MAX_LAYER;
|
||||
if( sceneIdx < 0 )
|
||||
sceneIdx += total;
|
||||
|
||||
auto layer = createLayer(sceneIdx);
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
Layer* restartAction()
|
||||
{
|
||||
auto layer = createLayer(sceneIdx);
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
|
||||
void ProgressActionsTestScene::runThisTest()
|
||||
{
|
||||
addChild(nextAction());
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteDemo
|
||||
|
@ -108,44 +55,14 @@ std::string SpriteDemo::title() const
|
|||
return "ActionsProgressTest";
|
||||
}
|
||||
|
||||
std::string SpriteDemo::subtitle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
void SpriteDemo::onEnter()
|
||||
{
|
||||
BaseTest::onEnter();
|
||||
TestCase::onEnter();
|
||||
|
||||
auto background = LayerColor::create(Color4B(255,0,0,255));
|
||||
addChild(background, -10);
|
||||
}
|
||||
|
||||
void SpriteDemo::restartCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ProgressActionsTestScene();
|
||||
s->addChild(restartAction());
|
||||
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void SpriteDemo::nextCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ProgressActionsTestScene();
|
||||
s->addChild( nextAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void SpriteDemo::backCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ProgressActionsTestScene();
|
||||
s->addChild( backAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// SpriteProgressToRadial
|
||||
|
|
|
@ -29,24 +29,23 @@
|
|||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
|
||||
class SpriteDemo : public BaseTest
|
||||
DEFINE_TEST_SUITE(ActionsProgressTests);
|
||||
|
||||
class SpriteDemo : public TestCase
|
||||
{
|
||||
public:
|
||||
SpriteDemo(void);
|
||||
~SpriteDemo(void);
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void onEnter() override;
|
||||
|
||||
void restartCallback(Ref* sender) override;
|
||||
void nextCallback(Ref* sender) override;
|
||||
void backCallback(Ref* sender) override;
|
||||
};
|
||||
|
||||
class SpriteProgressToRadial : public SpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteProgressToRadial);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -54,6 +53,8 @@ public:
|
|||
class SpriteProgressToHorizontal : public SpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteProgressToHorizontal);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -61,6 +62,8 @@ public:
|
|||
class SpriteProgressToVertical : public SpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteProgressToVertical);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -68,6 +71,8 @@ public:
|
|||
class SpriteProgressToRadialMidpointChanged : public SpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteProgressToRadialMidpointChanged);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -75,6 +80,8 @@ public:
|
|||
class SpriteProgressBarVarious : public SpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteProgressBarVarious);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -82,6 +89,8 @@ public:
|
|||
class SpriteProgressBarTintAndFade : public SpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteProgressBarTintAndFade);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
@ -89,14 +98,10 @@ public:
|
|||
class SpriteProgressWithSpriteFrame : public SpriteDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteProgressWithSpriteFrame);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class ProgressActionsTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
#endif // _ACTIONS__PROGRESS_TEST_H_
|
||||
|
|
|
@ -31,112 +31,69 @@
|
|||
#include "renderer/CCCustomCommand.h"
|
||||
#include "renderer/CCGroupCommand.h"
|
||||
|
||||
static std::function<Layer*()> createFunctions[] = {
|
||||
|
||||
CL(ActionManual),
|
||||
CL(ActionMove),
|
||||
CL(ActionMove3D),
|
||||
CL(ActionRotate),
|
||||
CL(ActionRotateBy3D),
|
||||
CL(ActionScale),
|
||||
CL(ActionSkew),
|
||||
CL(ActionRotationalSkew),
|
||||
CL(ActionRotationalSkewVSStandardSkew),
|
||||
CL(ActionSkewRotateScale),
|
||||
CL(ActionJump),
|
||||
CL(ActionCardinalSpline),
|
||||
CL(ActionCatmullRom),
|
||||
CL(ActionBezier),
|
||||
CL(ActionBlink),
|
||||
CL(ActionFade),
|
||||
CL(ActionTint),
|
||||
CL(ActionAnimate),
|
||||
CL(ActionSequence),
|
||||
CL(ActionSequence2),
|
||||
CL(ActionRemoveSelf),
|
||||
CL(ActionSpawn),
|
||||
CL(ActionReverse),
|
||||
CL(ActionDelayTime),
|
||||
CL(ActionRepeat),
|
||||
CL(ActionRepeatForever),
|
||||
CL(ActionRotateToRepeat),
|
||||
CL(ActionRotateJerk),
|
||||
CL(ActionCallFunction),
|
||||
CL(ActionCallFuncN),
|
||||
CL(ActionCallFuncND),
|
||||
CL(ActionCallFuncO),
|
||||
CL(ActionReverseSequence),
|
||||
CL(ActionReverseSequence2),
|
||||
CL(ActionOrbit),
|
||||
CL(ActionFollow),
|
||||
CL(ActionTargeted),
|
||||
CL(ActionTargetedReverse),
|
||||
CL(ActionMoveStacked),
|
||||
CL(ActionMoveJumpStacked),
|
||||
CL(ActionMoveBezierStacked),
|
||||
CL(ActionCardinalSplineStacked),
|
||||
CL(ActionCatmullRomStacked),
|
||||
CL(PauseResumeActions),
|
||||
CL(Issue1305),
|
||||
CL(Issue1305_2),
|
||||
CL(Issue1288),
|
||||
CL(Issue1288_2),
|
||||
CL(Issue1327),
|
||||
CL(Issue1398),
|
||||
CL(Issue2599)
|
||||
};
|
||||
|
||||
static int sceneIdx=-1;
|
||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||
|
||||
static Layer* nextAction()
|
||||
ActionsTests::ActionsTests()
|
||||
{
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_LAYER;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
ADD_TEST_CASE(ActionManual);
|
||||
ADD_TEST_CASE(ActionMove);
|
||||
ADD_TEST_CASE(ActionMove3D);
|
||||
ADD_TEST_CASE(ActionRotate);
|
||||
ADD_TEST_CASE(ActionRotateBy3D);
|
||||
ADD_TEST_CASE(ActionScale);
|
||||
ADD_TEST_CASE(ActionSkew);
|
||||
ADD_TEST_CASE(ActionRotationalSkew);
|
||||
ADD_TEST_CASE(ActionRotationalSkewVSStandardSkew);
|
||||
ADD_TEST_CASE(ActionSkewRotateScale);
|
||||
ADD_TEST_CASE(ActionJump);
|
||||
ADD_TEST_CASE(ActionCardinalSpline);
|
||||
ADD_TEST_CASE(ActionCatmullRom);
|
||||
ADD_TEST_CASE(ActionBezier);
|
||||
ADD_TEST_CASE(ActionBlink);
|
||||
ADD_TEST_CASE(ActionFade);
|
||||
ADD_TEST_CASE(ActionTint);
|
||||
ADD_TEST_CASE(ActionAnimate);
|
||||
ADD_TEST_CASE(ActionSequence);
|
||||
ADD_TEST_CASE(ActionSequence2);
|
||||
ADD_TEST_CASE(ActionRemoveSelf);
|
||||
ADD_TEST_CASE(ActionSpawn);
|
||||
ADD_TEST_CASE(ActionReverse);
|
||||
ADD_TEST_CASE(ActionDelayTime);
|
||||
ADD_TEST_CASE(ActionRepeat);
|
||||
ADD_TEST_CASE(ActionRepeatForever);
|
||||
ADD_TEST_CASE(ActionRotateToRepeat);
|
||||
ADD_TEST_CASE(ActionRotateJerk);
|
||||
ADD_TEST_CASE(ActionCallFunction);
|
||||
ADD_TEST_CASE(ActionCallFuncN);
|
||||
ADD_TEST_CASE(ActionCallFuncND);
|
||||
ADD_TEST_CASE(ActionCallFuncO);
|
||||
ADD_TEST_CASE(ActionReverseSequence);
|
||||
ADD_TEST_CASE(ActionReverseSequence2);
|
||||
ADD_TEST_CASE(ActionOrbit);
|
||||
ADD_TEST_CASE(ActionFollow);
|
||||
ADD_TEST_CASE(ActionTargeted);
|
||||
ADD_TEST_CASE(ActionTargetedReverse);
|
||||
ADD_TEST_CASE(ActionMoveStacked);
|
||||
ADD_TEST_CASE(ActionMoveJumpStacked);
|
||||
ADD_TEST_CASE(ActionMoveBezierStacked);
|
||||
ADD_TEST_CASE(ActionCardinalSplineStacked);
|
||||
ADD_TEST_CASE(ActionCatmullRomStacked);
|
||||
ADD_TEST_CASE(PauseResumeActions);
|
||||
ADD_TEST_CASE(Issue1305);
|
||||
ADD_TEST_CASE(Issue1305_2);
|
||||
ADD_TEST_CASE(Issue1288);
|
||||
ADD_TEST_CASE(Issue1288_2);
|
||||
ADD_TEST_CASE(Issue1327);
|
||||
ADD_TEST_CASE(Issue1398);
|
||||
ADD_TEST_CASE(Issue2599)
|
||||
}
|
||||
|
||||
static Layer* backAction()
|
||||
{
|
||||
sceneIdx--;
|
||||
int total = MAX_LAYER;
|
||||
if( sceneIdx < 0 )
|
||||
sceneIdx += total;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
static Layer* restartAction()
|
||||
{
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
void ActionsTestScene::runThisTest()
|
||||
{
|
||||
sceneIdx = -1;
|
||||
addChild(nextAction());
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
||||
|
||||
std::string ActionsDemo::title() const
|
||||
{
|
||||
return "ActionsTest";
|
||||
}
|
||||
|
||||
std::string ActionsDemo::subtitle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
void ActionsDemo::onEnter()
|
||||
{
|
||||
BaseTest::onEnter();
|
||||
TestCase::onEnter();
|
||||
|
||||
// Or you can create an sprite using a filename. only PNG is supported now. Probably TIFF too
|
||||
_grossini = Sprite::create(s_pathGrossini);
|
||||
|
@ -163,31 +120,7 @@ void ActionsDemo::onExit()
|
|||
_tamara->release();
|
||||
_kathia->release();
|
||||
|
||||
BaseTest::onExit();
|
||||
}
|
||||
|
||||
void ActionsDemo::restartCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ActionsTestScene();
|
||||
s->addChild( restartAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void ActionsDemo::nextCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ActionsTestScene();
|
||||
s->addChild( nextAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void ActionsDemo::backCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ActionsTestScene();
|
||||
s->addChild( backAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
TestCase::onExit();
|
||||
}
|
||||
|
||||
void ActionsDemo::centerSprites(unsigned int numberOfSprites)
|
||||
|
@ -1464,9 +1397,9 @@ void ActionStacked::onEnter()
|
|||
|
||||
this->centerSprites(0);
|
||||
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
/*auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesEnded = CC_CALLBACK_2(ActionStacked::onTouchesEnded, this);
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);*/
|
||||
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
this->addNewSpriteWithCoords(Vec2(s.width/2, s.height/2));
|
||||
|
@ -1492,13 +1425,14 @@ void ActionStacked::runActionsInSprite(Sprite *sprite)
|
|||
// override me
|
||||
}
|
||||
|
||||
/*
|
||||
void ActionStacked::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
||||
{
|
||||
for ( auto &touch: touches ) {
|
||||
auto location = touch->getLocation();
|
||||
addNewSpriteWithCoords( location );
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
std::string ActionStacked::title() const
|
||||
{
|
||||
|
|
|
@ -28,21 +28,12 @@
|
|||
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
////----#include "cocos2d.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
DEFINE_TEST_SUITE(ActionsTests);
|
||||
|
||||
// the class inherit from TestScene
|
||||
// every Scene each test used must inherit from TestScene,
|
||||
// make sure the test have the menu item for back to main menu
|
||||
class ActionsTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
class ActionsDemo : public BaseTest
|
||||
class ActionsDemo : public TestCase
|
||||
{
|
||||
protected:
|
||||
Sprite* _grossini;
|
||||
|
@ -55,11 +46,6 @@ public:
|
|||
void centerSprites(unsigned int numberOfSprites);
|
||||
void alignSpritesLeft(unsigned int numberOfSprites);
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void restartCallback(Ref* sender) override;
|
||||
void nextCallback(Ref* sender) override;
|
||||
void backCallback(Ref* sender) override;
|
||||
};
|
||||
|
||||
class ActionManual : public ActionsDemo
|
||||
|
@ -421,7 +407,7 @@ public:
|
|||
virtual std::string subtitle() const override;
|
||||
virtual void addNewSpriteWithCoords(Vec2 p);
|
||||
virtual void runActionsInSprite(Sprite* sprite);
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
|
||||
//void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
|
||||
};
|
||||
|
||||
class ActionMoveStacked : public ActionStacked
|
||||
|
|
|
@ -27,189 +27,131 @@
|
|||
#include "cocos2d.h"
|
||||
#include <chrono>
|
||||
|
||||
namespace AllocatorTestNS
|
||||
AllocatorTests::AllocatorTests()
|
||||
{
|
||||
|
||||
ADD_TEST_CASE(AllocatorTest);
|
||||
}
|
||||
|
||||
#define kNumberOfInstances 100000
|
||||
#define kObjectSize 952 // sizeof(Sprite)
|
||||
|
||||
namespace
|
||||
{
|
||||
class Test1;
|
||||
|
||||
class Test1
|
||||
{
|
||||
public:
|
||||
|
||||
Test1()
|
||||
{
|
||||
memset(bytes, 0, sizeof(bytes));
|
||||
}
|
||||
uint8_t bytes[kObjectSize];
|
||||
|
||||
#if CC_ENABLE_ALLOCATOR
|
||||
typedef cocos2d::allocator::AllocatorStrategyPool<Test1> tAllocator;
|
||||
static tAllocator _allocator;
|
||||
#endif // CC_ENABLE_ALLOCATOR
|
||||
CC_USE_ALLOCATOR_POOL(Test1, _allocator);
|
||||
};
|
||||
|
||||
class Test2
|
||||
{
|
||||
public:
|
||||
|
||||
Test2()
|
||||
{
|
||||
memset(bytes, 0, sizeof(bytes));
|
||||
}
|
||||
uint8_t bytes[kObjectSize];
|
||||
};
|
||||
|
||||
#if CC_ENABLE_ALLOCATOR
|
||||
Test1::tAllocator Test1::_allocator("Test1", kNumberOfInstances);
|
||||
#endif // CC_ENABLE_ALLOCATOR
|
||||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
static std::function<Layer*()> createFunctions[] =
|
||||
{
|
||||
CL(AllocatorTest)
|
||||
};
|
||||
|
||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||
|
||||
static Layer* nextAllocatorTestAction()
|
||||
{
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_LAYER;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
static Layer* backAllocatorTestAction()
|
||||
{
|
||||
sceneIdx--;
|
||||
int total = MAX_LAYER;
|
||||
if( sceneIdx < 0 )
|
||||
sceneIdx += total;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
static Layer* restartAllocatorTestAction()
|
||||
{
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
//
|
||||
// AllocatorTest
|
||||
//
|
||||
|
||||
AllocatorTest::AllocatorTest()
|
||||
{
|
||||
typedef std::vector<Test1*> tTest1Container;
|
||||
typedef std::vector<Test2*> tTest2Container;
|
||||
|
||||
tTest1Container test1Container;
|
||||
test1Container.reserve(kNumberOfInstances);
|
||||
|
||||
tTest2Container test2Container;
|
||||
test2Container.reserve(kNumberOfInstances);
|
||||
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> alloc1Start, alloc1End, alloc2Start, alloc2End;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> free1Start, free1End, free2Start, free2End;
|
||||
|
||||
alloc1Start = std::chrono::high_resolution_clock::now();
|
||||
for (int i = 0; i < kNumberOfInstances; ++i)
|
||||
test1Container.push_back(new Test1);
|
||||
alloc1End = std::chrono::high_resolution_clock::now();
|
||||
|
||||
free1Start = std::chrono::high_resolution_clock::now();
|
||||
for (int i = 0; i < kNumberOfInstances; ++i)
|
||||
delete test1Container[i];
|
||||
free1End = std::chrono::high_resolution_clock::now();
|
||||
test1Container.clear();
|
||||
}
|
||||
|
||||
alloc2Start = std::chrono::high_resolution_clock::now();
|
||||
for (int i = 0; i < kNumberOfInstances; ++i)
|
||||
test2Container.push_back(new Test2);
|
||||
alloc2End = std::chrono::high_resolution_clock::now();
|
||||
//
|
||||
// AllocatorTest
|
||||
//
|
||||
|
||||
AllocatorTest::AllocatorTest()
|
||||
{
|
||||
typedef std::vector<Test1*> tTest1Container;
|
||||
typedef std::vector<Test2*> tTest2Container;
|
||||
|
||||
tTest1Container test1Container;
|
||||
test1Container.reserve(kNumberOfInstances);
|
||||
|
||||
tTest2Container test2Container;
|
||||
test2Container.reserve(kNumberOfInstances);
|
||||
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> alloc1Start, alloc1End, alloc2Start, alloc2End;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> free1Start, free1End, free2Start, free2End;
|
||||
|
||||
alloc1Start = std::chrono::high_resolution_clock::now();
|
||||
for (int i = 0; i < kNumberOfInstances; ++i)
|
||||
test1Container.push_back(new Test1);
|
||||
alloc1End = std::chrono::high_resolution_clock::now();
|
||||
|
||||
free1Start = std::chrono::high_resolution_clock::now();
|
||||
for (int i = 0; i < kNumberOfInstances; ++i)
|
||||
delete test1Container[i];
|
||||
free1End = std::chrono::high_resolution_clock::now();
|
||||
test1Container.clear();
|
||||
|
||||
alloc2Start = std::chrono::high_resolution_clock::now();
|
||||
for (int i = 0; i < kNumberOfInstances; ++i)
|
||||
test2Container.push_back(new Test2);
|
||||
alloc2End = std::chrono::high_resolution_clock::now();
|
||||
|
||||
|
||||
free2Start = std::chrono::high_resolution_clock::now();
|
||||
for (int i = 0; i < kNumberOfInstances; ++i)
|
||||
delete test2Container[i];
|
||||
free2End = std::chrono::high_resolution_clock::now();
|
||||
|
||||
test2Container.clear();
|
||||
|
||||
std::chrono::duration<double> elapsed_seconds_alloc1 = alloc1End - alloc1Start;
|
||||
std::chrono::duration<double> elapsed_seconds_alloc2 = alloc2End - alloc2Start;
|
||||
std::chrono::duration<double> elapsed_seconds_free1 = free1End - free1Start;
|
||||
std::chrono::duration<double> elapsed_seconds_free2 = free2End - free2Start;
|
||||
|
||||
char buf[1000];
|
||||
|
||||
const float x_start = 240;
|
||||
const float y_start = 100;
|
||||
const float y_delta = 20;
|
||||
float y = 0;
|
||||
|
||||
sprintf(buf, "alloc1 %f", elapsed_seconds_alloc1.count());
|
||||
auto alloc1 = Label::createWithSystemFont(buf, "Helvetica", 12);
|
||||
alloc1->setPosition(x_start, y++ * y_delta + y_start);
|
||||
addChild(alloc1);
|
||||
|
||||
sprintf(buf, "alloc2 %f", elapsed_seconds_alloc2.count());
|
||||
auto alloc2 = Label::createWithSystemFont(buf, "Helvetica", 12);
|
||||
alloc2->setPosition(x_start, y++ * y_delta + y_start);
|
||||
addChild(alloc2);
|
||||
|
||||
sprintf(buf, "free1 %f", elapsed_seconds_free1.count());
|
||||
auto free1 = Label::createWithSystemFont(buf, "Helvetica", 12);
|
||||
free1->setPosition(x_start, y++ * y_delta + y_start);
|
||||
addChild(free1);
|
||||
|
||||
sprintf(buf, "free2 %f", elapsed_seconds_free2.count());
|
||||
auto free2 = Label::createWithSystemFont(buf, "Helvetica", 12);
|
||||
free2->setPosition(x_start, y++ * y_delta + y_start);
|
||||
addChild(free2);
|
||||
}
|
||||
|
||||
AllocatorTest::~AllocatorTest()
|
||||
{
|
||||
}
|
||||
|
||||
std::string AllocatorTest::title() const
|
||||
{
|
||||
return "Allocator Test";
|
||||
}
|
||||
|
||||
std::string AllocatorTest::subtitle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
void AllocatorTest::restartCallback( Ref* sender )
|
||||
{
|
||||
auto s = new AllocatorTestScene();
|
||||
s->addChild(restartAllocatorTestAction());
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void AllocatorTest::nextCallback( Ref* sender )
|
||||
{
|
||||
auto s = new AllocatorTestScene();
|
||||
s->addChild( nextAllocatorTestAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void AllocatorTest::backCallback( Ref* sender )
|
||||
{
|
||||
auto s = new AllocatorTestScene();
|
||||
s->addChild( backAllocatorTestAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void AllocatorTest::onEnter()
|
||||
{
|
||||
BaseTest::onEnter();
|
||||
}
|
||||
|
||||
void AllocatorTest::onExit()
|
||||
{
|
||||
BaseTest::onExit();
|
||||
}
|
||||
|
||||
void AllocatorTest::update(float delta)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// AllocatorTestScene
|
||||
//
|
||||
|
||||
AllocatorTestScene::AllocatorTestScene()
|
||||
{
|
||||
}
|
||||
|
||||
void AllocatorTestScene::runThisTest()
|
||||
{
|
||||
auto layer = nextAllocatorTestAction();
|
||||
addChild(layer);
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
||||
} // AllocatorTestNS
|
||||
free2Start = std::chrono::high_resolution_clock::now();
|
||||
for (int i = 0; i < kNumberOfInstances; ++i)
|
||||
delete test2Container[i];
|
||||
free2End = std::chrono::high_resolution_clock::now();
|
||||
|
||||
test2Container.clear();
|
||||
|
||||
std::chrono::duration<double> elapsed_seconds_alloc1 = alloc1End - alloc1Start;
|
||||
std::chrono::duration<double> elapsed_seconds_alloc2 = alloc2End - alloc2Start;
|
||||
std::chrono::duration<double> elapsed_seconds_free1 = free1End - free1Start;
|
||||
std::chrono::duration<double> elapsed_seconds_free2 = free2End - free2Start;
|
||||
|
||||
char buf[1000];
|
||||
|
||||
const float x_start = 240;
|
||||
const float y_start = 100;
|
||||
const float y_delta = 20;
|
||||
float y = 0;
|
||||
|
||||
sprintf(buf, "alloc1 %f", elapsed_seconds_alloc1.count());
|
||||
auto alloc1 = Label::createWithSystemFont(buf, "Helvetica", 12);
|
||||
alloc1->setPosition(x_start, y++ * y_delta + y_start);
|
||||
addChild(alloc1);
|
||||
|
||||
sprintf(buf, "alloc2 %f", elapsed_seconds_alloc2.count());
|
||||
auto alloc2 = Label::createWithSystemFont(buf, "Helvetica", 12);
|
||||
alloc2->setPosition(x_start, y++ * y_delta + y_start);
|
||||
addChild(alloc2);
|
||||
|
||||
sprintf(buf, "free1 %f", elapsed_seconds_free1.count());
|
||||
auto free1 = Label::createWithSystemFont(buf, "Helvetica", 12);
|
||||
free1->setPosition(x_start, y++ * y_delta + y_start);
|
||||
addChild(free1);
|
||||
|
||||
sprintf(buf, "free2 %f", elapsed_seconds_free2.count());
|
||||
auto free2 = Label::createWithSystemFont(buf, "Helvetica", 12);
|
||||
free2->setPosition(x_start, y++ * y_delta + y_start);
|
||||
addChild(free2);
|
||||
}
|
||||
|
||||
AllocatorTest::~AllocatorTest()
|
||||
{
|
||||
}
|
||||
|
||||
std::string AllocatorTest::title() const
|
||||
{
|
||||
return "Allocator Test";
|
||||
}
|
||||
|
|
|
@ -29,71 +29,15 @@
|
|||
#include "../BaseTest.h"
|
||||
#include "base/allocator/CCAllocatorStrategyPool.h"
|
||||
|
||||
namespace AllocatorTestNS
|
||||
DEFINE_TEST_SUITE(AllocatorTests);
|
||||
|
||||
class AllocatorTest : public TestCase
|
||||
{
|
||||
|
||||
//
|
||||
// Test Classes
|
||||
//
|
||||
|
||||
#define kNumberOfInstances 100000
|
||||
#define kObjectSize 952 // sizeof(Sprite)
|
||||
|
||||
class Test1;
|
||||
|
||||
class Test1
|
||||
{
|
||||
public:
|
||||
|
||||
Test1()
|
||||
{
|
||||
memset(bytes, 0, sizeof(bytes));
|
||||
}
|
||||
uint8_t bytes[kObjectSize];
|
||||
|
||||
#if CC_ENABLE_ALLOCATOR
|
||||
typedef cocos2d::allocator::AllocatorStrategyPool<Test1> tAllocator;
|
||||
static tAllocator _allocator;
|
||||
#endif // CC_ENABLE_ALLOCATOR
|
||||
CC_USE_ALLOCATOR_POOL(Test1, _allocator);
|
||||
};
|
||||
|
||||
class Test2
|
||||
{
|
||||
public:
|
||||
|
||||
Test2()
|
||||
{
|
||||
memset(bytes, 0, sizeof(bytes));
|
||||
}
|
||||
uint8_t bytes[kObjectSize];
|
||||
};
|
||||
|
||||
class AllocatorTest : public BaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(AllocatorTest);
|
||||
AllocatorTest();
|
||||
virtual ~AllocatorTest();
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
virtual void restartCallback(Ref* sender) override;
|
||||
virtual void nextCallback(Ref* sender) override;
|
||||
virtual void backCallback(Ref* sender) override;
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
|
||||
virtual void update(float delta) override;
|
||||
};
|
||||
|
||||
class AllocatorTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
AllocatorTestScene();
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
} // AllocatorTestNS
|
||||
public:
|
||||
CREATE_FUNC(AllocatorTest);
|
||||
|
||||
AllocatorTest();
|
||||
virtual ~AllocatorTest();
|
||||
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
|
|
|
@ -29,48 +29,10 @@
|
|||
#include <algorithm>
|
||||
#include "../testResource.h"
|
||||
|
||||
enum
|
||||
BillBoardTests::BillBoardTests()
|
||||
{
|
||||
IDC_NEXT = 100,
|
||||
IDC_BACK,
|
||||
IDC_RESTART
|
||||
};
|
||||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
|
||||
static std::function<Layer*()> createFunctions[] =
|
||||
{
|
||||
CL(BillBoardRotationTest),
|
||||
CL(BillBoardTest)
|
||||
};
|
||||
|
||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||
|
||||
static Layer* nextTest()
|
||||
{
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_LAYER;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
static Layer* backTest()
|
||||
{
|
||||
sceneIdx--;
|
||||
int total = MAX_LAYER;
|
||||
if( sceneIdx < 0 )
|
||||
sceneIdx += total;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
static Layer* restartTest()
|
||||
{
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
ADD_TEST_CASE(BillBoardRotationTest);
|
||||
ADD_TEST_CASE(BillBoardTest);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
@ -137,31 +99,6 @@ std::string BillBoardRotationTest::subtitle() const
|
|||
return "All the sprites should still facing camera";
|
||||
}
|
||||
|
||||
void BillBoardRotationTest::restartCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) BillBoardTestScene();
|
||||
s->addChild(restartTest());
|
||||
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void BillBoardRotationTest::nextCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) BillBoardTestScene();
|
||||
s->addChild(nextTest());
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void BillBoardRotationTest::backCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) BillBoardTestScene();
|
||||
s->addChild(backTest());
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Billboard Rendering Test
|
||||
|
@ -171,9 +108,9 @@ BillBoardTest::BillBoardTest()
|
|||
: _camera(nullptr)
|
||||
{
|
||||
//Create touch listener
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
/*auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesMoved = CC_CALLBACK_2(BillBoardTest::onTouchesMoved, this);
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);*/
|
||||
|
||||
auto layer3D=Layer::create();
|
||||
addChild(layer3D,0);
|
||||
|
@ -333,6 +270,8 @@ void BillBoardTest::addNewAniBillBoradWithCoords(Vec3 p)
|
|||
void BillBoardTest::update(float dt)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
void BillBoardTest::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
|
||||
{
|
||||
if(touches.size()==1)
|
||||
|
@ -355,43 +294,11 @@ void BillBoardTest::onTouchesMoved(const std::vector<Touch*>& touches, Event* ev
|
|||
cameraPos+=cameraRightDir*newPos.x*0.5;
|
||||
_camera->setPosition3D(cameraPos);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
void BillBoardTest::rotateCameraCallback(Ref* sender,float value)
|
||||
{
|
||||
Vec3 rotation3D= _camera->getRotation3D();
|
||||
rotation3D.y+= value;
|
||||
_camera->setRotation3D(rotation3D);
|
||||
}
|
||||
|
||||
|
||||
void BillBoardTest::restartCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) BillBoardTestScene();
|
||||
s->addChild(restartTest());
|
||||
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void BillBoardTest::nextCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) BillBoardTestScene();
|
||||
s->addChild(nextTest());
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void BillBoardTest::backCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) BillBoardTestScene();
|
||||
s->addChild(backTest());
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void BillBoardTestScene::runThisTest()
|
||||
{
|
||||
auto layer = nextTest();
|
||||
addChild(layer);
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace cocos2d {
|
|||
class Camera;
|
||||
}
|
||||
|
||||
class BillBoardRotationTest : public BaseTest
|
||||
class BillBoardRotationTest : public TestCase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(BillBoardRotationTest);
|
||||
|
@ -43,14 +43,10 @@ public:
|
|||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
virtual void restartCallback(Ref* sender) override;
|
||||
virtual void nextCallback(Ref* sender) override;
|
||||
virtual void backCallback(Ref* sender) override;
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
class BillBoardTest : public BaseTest
|
||||
class BillBoardTest : public TestCase
|
||||
{
|
||||
public:
|
||||
virtual ~BillBoardTest(void);
|
||||
|
@ -62,14 +58,10 @@ public:
|
|||
void addNewBillBoradWithCoords(Vec3 p);
|
||||
void addNewAniBillBoradWithCoords(Vec3 p);
|
||||
void rotateCameraCallback(Ref* sender,float value);
|
||||
void onTouchesMoved(const std::vector<Touch*>& touches, Event* event) override;
|
||||
//void onTouchesMoved(const std::vector<Touch*>& touches, Event* event) override;
|
||||
|
||||
void menuCallback_orientedPoint(Ref* sender);
|
||||
void menuCallback_orientedPlane(Ref* sender);
|
||||
|
||||
virtual void restartCallback(Ref* sender) override;
|
||||
virtual void nextCallback(Ref* sender) override;
|
||||
virtual void backCallback(Ref* sender) override;
|
||||
|
||||
protected:
|
||||
Camera* _camera;
|
||||
|
@ -78,10 +70,6 @@ protected:
|
|||
std::vector<BillBoard*> _billboards;
|
||||
};
|
||||
|
||||
class BillBoardTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
DEFINE_TEST_SUITE(BillBoardTests);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -12,7 +12,7 @@ enum {
|
|||
kTagParentNode = 1,
|
||||
};
|
||||
|
||||
Box2DTestLayer::Box2DTestLayer()
|
||||
Box2DTest::Box2DTest()
|
||||
: _spriteTexture(nullptr)
|
||||
, world(nullptr)
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ Box2DTestLayer::Box2DTestLayer()
|
|||
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
||||
|
||||
auto touchListener = EventListenerTouchAllAtOnce::create();
|
||||
touchListener->onTouchesEnded = CC_CALLBACK_2(Box2DTestLayer::onTouchesEnded, this);
|
||||
touchListener->onTouchesEnded = CC_CALLBACK_2(Box2DTest::onTouchesEnded, this);
|
||||
dispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
|
||||
|
||||
// init physics
|
||||
|
@ -60,14 +60,14 @@ Box2DTestLayer::Box2DTestLayer()
|
|||
#endif
|
||||
}
|
||||
|
||||
Box2DTestLayer::~Box2DTestLayer()
|
||||
Box2DTest::~Box2DTest()
|
||||
{
|
||||
CC_SAFE_DELETE(world);
|
||||
|
||||
//delete _debugDraw;
|
||||
}
|
||||
|
||||
void Box2DTestLayer::initPhysics()
|
||||
void Box2DTest::initPhysics()
|
||||
{
|
||||
b2Vec2 gravity;
|
||||
gravity.Set(0.0f, -10.0f);
|
||||
|
@ -119,15 +119,10 @@ void Box2DTestLayer::initPhysics()
|
|||
groundBody->CreateFixture(&groundBox,0);
|
||||
}
|
||||
|
||||
void Box2DTestLayer::createResetButton()
|
||||
void Box2DTest::createResetButton()
|
||||
{
|
||||
auto reset = MenuItemImage::create("Images/r1.png", "Images/r2.png", [](Ref *sender) {
|
||||
auto s = new (std::nothrow) Box2DTestScene();
|
||||
auto child = new (std::nothrow) Box2DTestLayer();
|
||||
s->addChild(child);
|
||||
child->release();
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
auto reset = MenuItemImage::create("Images/r1.png", "Images/r2.png", [&](Ref *sender) {
|
||||
getTestSuite()->restartCurrTest();
|
||||
});
|
||||
|
||||
auto menu = Menu::create(reset, nullptr);
|
||||
|
@ -137,14 +132,14 @@ void Box2DTestLayer::createResetButton()
|
|||
|
||||
}
|
||||
|
||||
void Box2DTestLayer::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
||||
void Box2DTest::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
||||
{
|
||||
//
|
||||
// IMPORTANT:
|
||||
// This is only for debug purposes
|
||||
// It is recommend to disable it
|
||||
//
|
||||
Layer::draw(renderer, transform, flags);
|
||||
Scene::draw(renderer, transform, flags);
|
||||
|
||||
#if CC_ENABLE_BOX2D_INTEGRATION
|
||||
GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION );
|
||||
|
@ -155,7 +150,7 @@ void Box2DTestLayer::draw(Renderer *renderer, const Mat4 &transform, uint32_t fl
|
|||
_modelViewMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
||||
|
||||
_customCommand.init(_globalZOrder);
|
||||
_customCommand.func = CC_CALLBACK_0(Box2DTestLayer::onDraw, this);
|
||||
_customCommand.func = CC_CALLBACK_0(Box2DTest::onDraw, this);
|
||||
renderer->addCommand(&_customCommand);
|
||||
|
||||
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
||||
|
@ -163,7 +158,7 @@ void Box2DTestLayer::draw(Renderer *renderer, const Mat4 &transform, uint32_t fl
|
|||
}
|
||||
|
||||
#if CC_ENABLE_BOX2D_INTEGRATION
|
||||
void Box2DTestLayer::onDraw()
|
||||
void Box2DTest::onDraw()
|
||||
{
|
||||
Director* director = Director::getInstance();
|
||||
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
|
||||
|
@ -175,7 +170,7 @@ void Box2DTestLayer::onDraw()
|
|||
}
|
||||
#endif
|
||||
|
||||
void Box2DTestLayer::addNewSpriteAtPosition(Vec2 p)
|
||||
void Box2DTest::addNewSpriteAtPosition(Vec2 p)
|
||||
{
|
||||
CCLOG("Add sprite %0.2f x %02.f",p.x,p.y);
|
||||
|
||||
|
@ -214,7 +209,7 @@ void Box2DTestLayer::addNewSpriteAtPosition(Vec2 p)
|
|||
}
|
||||
|
||||
|
||||
void Box2DTestLayer::update(float dt)
|
||||
void Box2DTest::update(float dt)
|
||||
{
|
||||
//It is recommended that a fixed time step is used with Box2D for stability
|
||||
//of the simulation, however, we are using a variable time step here.
|
||||
|
@ -229,7 +224,7 @@ void Box2DTestLayer::update(float dt)
|
|||
world->Step(dt, velocityIterations, positionIterations);
|
||||
}
|
||||
|
||||
void Box2DTestLayer::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
||||
void Box2DTest::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
||||
{
|
||||
//Add a new body/atlas sprite at the touched location
|
||||
|
||||
|
@ -245,7 +240,7 @@ void Box2DTestLayer::onTouchesEnded(const std::vector<Touch*>& touches, Event* e
|
|||
}
|
||||
|
||||
/*
|
||||
void Box2DTestLayer::accelerometer(UIAccelerometer* accelerometer, Acceleration* acceleration)
|
||||
void Box2DTest::accelerometer(UIAccelerometer* accelerometer, Acceleration* acceleration)
|
||||
{
|
||||
static float prevX=0, prevY=0;
|
||||
|
||||
|
@ -266,12 +261,4 @@ void Box2DTestLayer::accelerometer(UIAccelerometer* accelerometer, Acceleration*
|
|||
}
|
||||
*/
|
||||
|
||||
void Box2DTestScene::runThisTest()
|
||||
{
|
||||
auto layer = new (std::nothrow) Box2DTestLayer();
|
||||
addChild(layer);
|
||||
layer->release();
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,17 +3,19 @@
|
|||
|
||||
#include "cocos2d.h"
|
||||
#include "Box2D/Box2D.h"
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
|
||||
class Box2DTestLayer : public Layer
|
||||
DEFINE_TEST_SUITE(Box2DTests);
|
||||
|
||||
class Box2DTest : public TestCase
|
||||
{
|
||||
Texture2D* _spriteTexture; // weak ref
|
||||
b2World* world;
|
||||
// GLESDebugDraw* _debugDraw;
|
||||
|
||||
public:
|
||||
Box2DTestLayer();
|
||||
~Box2DTestLayer();
|
||||
Box2DTest();
|
||||
~Box2DTest();
|
||||
|
||||
void initPhysics();
|
||||
void createResetButton();
|
||||
|
@ -21,7 +23,7 @@ public:
|
|||
|
||||
void addNewSpriteAtPosition(Vec2 p);
|
||||
void update(float dt) override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||
|
||||
#if CC_ENABLE_BOX2D_INTEGRATION
|
||||
protected:
|
||||
|
@ -31,10 +33,4 @@ protected:
|
|||
#endif
|
||||
} ;
|
||||
|
||||
class Box2DTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,38 +15,40 @@ enum
|
|||
kTagBox2DNode,
|
||||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// MenuLayer
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
enum
|
||||
Box2dTestBedSuite::Box2dTestBedSuite()
|
||||
{
|
||||
IDC_NEXT = 100,
|
||||
IDC_BACK,
|
||||
IDC_RESTART
|
||||
};
|
||||
for (int entryId = 0; entryId < g_totalEntries; ++entryId)
|
||||
{
|
||||
addTestCase(g_testEntries[entryId].name, [&](){
|
||||
return Box2dTestBed::createWithEntryID(entryId);
|
||||
});
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Box2dTestBed
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
MenuLayer::MenuLayer(void)
|
||||
Box2dTestBed::Box2dTestBed()
|
||||
{
|
||||
}
|
||||
|
||||
MenuLayer::~MenuLayer(void)
|
||||
Box2dTestBed::~Box2dTestBed()
|
||||
{
|
||||
_eventDispatcher->removeEventListener(_touchListener);
|
||||
}
|
||||
|
||||
MenuLayer* MenuLayer::menuWithEntryID(int entryId)
|
||||
Box2dTestBed* Box2dTestBed::createWithEntryID(int entryId)
|
||||
{
|
||||
auto layer = new (std::nothrow) MenuLayer();
|
||||
auto layer = new (std::nothrow) Box2dTestBed();
|
||||
layer->initWithEntryID(entryId);
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
bool MenuLayer::initWithEntryID(int entryId)
|
||||
bool Box2dTestBed::initWithEntryID(int entryId)
|
||||
{
|
||||
auto director = Director::getInstance();
|
||||
Vec2 visibleOrigin = director->getVisibleOrigin();
|
||||
|
@ -62,26 +64,13 @@ bool MenuLayer::initWithEntryID(int entryId)
|
|||
auto label = Label::createWithTTF(view->title().c_str(), "fonts/arial.ttf", 28);
|
||||
addChild(label, 1);
|
||||
label->setPosition(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height-50);
|
||||
|
||||
auto item1 = MenuItemImage::create("Images/b1.png", "Images/b2.png", CC_CALLBACK_1(MenuLayer::backCallback, this) );
|
||||
auto item2 = MenuItemImage::create("Images/r1.png","Images/r2.png", CC_CALLBACK_1( MenuLayer::restartCallback, this) );
|
||||
auto item3 = MenuItemImage::create("Images/f1.png", "Images/f2.png", CC_CALLBACK_1(MenuLayer::nextCallback, this) );
|
||||
|
||||
auto menu = Menu::create(item1, item2, item3, nullptr);
|
||||
|
||||
menu->setPosition( Vec2::ZERO );
|
||||
item1->setPosition(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2);
|
||||
item2->setPosition(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2);
|
||||
item3->setPosition(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2);
|
||||
|
||||
addChild(menu, 1);
|
||||
|
||||
// Adds touch event listener
|
||||
auto listener = EventListenerTouchOneByOne::create();
|
||||
listener->setSwallowTouches(true);
|
||||
|
||||
listener->onTouchBegan = CC_CALLBACK_2(MenuLayer::onTouchBegan, this);
|
||||
listener->onTouchMoved = CC_CALLBACK_2(MenuLayer::onTouchMoved, this);
|
||||
listener->onTouchBegan = CC_CALLBACK_2(Box2dTestBed::onTouchBegan, this);
|
||||
listener->onTouchMoved = CC_CALLBACK_2(Box2dTestBed::onTouchMoved, this);
|
||||
|
||||
_eventDispatcher->addEventListenerWithFixedPriority(listener, 1);
|
||||
|
||||
|
@ -90,62 +79,12 @@ bool MenuLayer::initWithEntryID(int entryId)
|
|||
return true;
|
||||
}
|
||||
|
||||
void MenuLayer::restartCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) Box2dTestBedScene();
|
||||
auto box = MenuLayer::menuWithEntryID(m_entryID);
|
||||
s->addChild( box );
|
||||
Director::getInstance()->replaceScene( s );
|
||||
s->release();
|
||||
}
|
||||
|
||||
void MenuLayer::nextCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) Box2dTestBedScene();
|
||||
int next = m_entryID + 1;
|
||||
if( next >= g_totalEntries)
|
||||
next = 0;
|
||||
auto box = MenuLayer::menuWithEntryID(next);
|
||||
s->addChild( box );
|
||||
Director::getInstance()->replaceScene( s );
|
||||
s->release();
|
||||
}
|
||||
|
||||
void MenuLayer::backCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) Box2dTestBedScene();
|
||||
int next = m_entryID - 1;
|
||||
if( next < 0 ) {
|
||||
next = g_totalEntries - 1;
|
||||
}
|
||||
|
||||
auto box = MenuLayer::menuWithEntryID(next);
|
||||
|
||||
s->addChild( box );
|
||||
Director::getInstance()->replaceScene( s );
|
||||
s->release();
|
||||
}
|
||||
|
||||
//void MenuLayer::registerWithTouchDispatcher()
|
||||
//{
|
||||
// auto director = Director::getInstance();
|
||||
// director->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
|
||||
//}
|
||||
|
||||
bool MenuLayer::onTouchBegan(Touch* touch, Event* event)
|
||||
bool Box2dTestBed::onTouchBegan(Touch* touch, Event* event)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//-(void) MenuLayer::ccTouchEnded:(UITouch *)touch withEvent:(Event *)event
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//-(void) MenuLayer::ccTouchCancelled:(UITouch *)touch withEvent:(Event *)event
|
||||
//{
|
||||
//}
|
||||
|
||||
void MenuLayer::onTouchMoved(Touch* touch, Event* event)
|
||||
void Box2dTestBed::onTouchMoved(Touch* touch, Event* event)
|
||||
{
|
||||
auto diff = touch->getDelta();
|
||||
auto node = getChildByTag( kTagBox2DNode );
|
||||
|
@ -233,13 +172,6 @@ Box2DView::~Box2DView()
|
|||
_eventDispatcher->removeEventListener(_keyboardListener);
|
||||
delete m_test;
|
||||
}
|
||||
//
|
||||
//void Box2DView::registerWithTouchDispatcher()
|
||||
//{
|
||||
// // higher priority than dragging
|
||||
// auto director = Director::getInstance();
|
||||
// director->getTouchDispatcher()->addTargetedDelegate(this, -10, true);
|
||||
//}
|
||||
|
||||
bool Box2DView::onTouchBegan(Touch* touch, Event* event)
|
||||
{
|
||||
|
@ -282,20 +214,3 @@ void Box2DView::onKeyReleased(EventKeyboard::KeyCode code, Event* event)
|
|||
log("onKeyReleased, keycode: %d", code);
|
||||
m_test->KeyboardUp(static_cast<unsigned char>(code));
|
||||
}
|
||||
|
||||
// void Box2DView::accelerometer(UIAccelerometer* accelerometer, Acceleration* acceleration)
|
||||
// {
|
||||
// //// Only run for valid values
|
||||
// //if (acceleration.y!=0 && acceleration.x!=0)
|
||||
// //{
|
||||
// // if (test) test->SetGravity((float)-acceleration.y,(float)acceleration.x);
|
||||
// //}
|
||||
// }
|
||||
|
||||
|
||||
void Box2dTestBedScene::runThisTest()
|
||||
{
|
||||
addChild(MenuLayer::menuWithEntryID(0));
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
|
|
@ -1,30 +1,25 @@
|
|||
#ifndef _BOX2D_VIEW_H_
|
||||
#define _BOX2D_VIEW_H_
|
||||
|
||||
//#include "cocos2d.h"
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
|
||||
class MenuLayer : public Layer
|
||||
DEFINE_TEST_SUITE(Box2dTestBedSuite);
|
||||
|
||||
class Box2dTestBed : public TestCase
|
||||
{
|
||||
int m_entryID;
|
||||
EventListenerTouchOneByOne* _touchListener;
|
||||
public:
|
||||
MenuLayer(void);
|
||||
virtual ~MenuLayer(void);
|
||||
static Box2dTestBed* createWithEntryID(int entryId);
|
||||
|
||||
Box2dTestBed();
|
||||
virtual ~Box2dTestBed();
|
||||
|
||||
bool initWithEntryID(int entryId);
|
||||
|
||||
void restartCallback(Ref* sender);
|
||||
void nextCallback(Ref* sender);
|
||||
void backCallback(Ref* sender);
|
||||
|
||||
|
||||
bool onTouchBegan(Touch* touch, Event* event);
|
||||
void onTouchMoved(Touch* touch, Event* event);
|
||||
|
||||
public:
|
||||
static MenuLayer* menuWithEntryID(int entryId);
|
||||
};
|
||||
|
||||
struct TestEntry;
|
||||
|
@ -60,10 +55,4 @@ protected:
|
|||
CustomCommand _customCmd;
|
||||
};
|
||||
|
||||
class Box2dTestBedScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -20,7 +20,7 @@ Scene* Bug1159Layer::scene()
|
|||
|
||||
bool Bug1159Layer::init()
|
||||
{
|
||||
if (BugsTestBaseLayer::init())
|
||||
if (BugsTestBase::init())
|
||||
{
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
|
||||
|
@ -62,5 +62,5 @@ void Bug1159Layer::callBack(Ref* sender)
|
|||
|
||||
void Bug1159Layer::onExit()
|
||||
{
|
||||
BugsTestBaseLayer::onExit();
|
||||
BugsTestBase::onExit();
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "BugsTest.h"
|
||||
|
||||
class Bug1159Layer : public BugsTestBaseLayer
|
||||
class Bug1159Layer : public BugsTestBase
|
||||
{
|
||||
public:
|
||||
virtual bool init() override;
|
||||
|
|
|
@ -32,7 +32,7 @@ int check_for_error( Vec2 p1, Vec2 p2, Vec2 p3, Vec2 p4, float s, float t )
|
|||
|
||||
bool Bug1174Layer::init()
|
||||
{
|
||||
if (BugsTestBaseLayer::init())
|
||||
if (BugsTestBase::init())
|
||||
{
|
||||
// // seed
|
||||
// srand(0);
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
|
||||
#include "BugsTest.h"
|
||||
|
||||
class Bug1174Layer : public BugsTestBaseLayer
|
||||
class Bug1174Layer : public BugsTestBase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Bug1174Layer);
|
||||
|
||||
virtual bool init() override;
|
||||
};
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
bool Bug350Layer::init()
|
||||
{
|
||||
if (BugsTestBaseLayer::init())
|
||||
if (BugsTestBase::init())
|
||||
{
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
auto background = Sprite::create("Hello.png");
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
|
||||
#include "BugsTest.h"
|
||||
|
||||
class Bug350Layer : public BugsTestBaseLayer
|
||||
class Bug350Layer : public BugsTestBase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Bug350Layer);
|
||||
|
||||
virtual bool init() override;
|
||||
};
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
bool Bug422Layer::init()
|
||||
{
|
||||
if (BugsTestBaseLayer::init())
|
||||
if (BugsTestBase::init())
|
||||
{
|
||||
reset();
|
||||
return true;
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
|
||||
#include "BugsTest.h"
|
||||
|
||||
class Bug422Layer : public BugsTestBaseLayer
|
||||
class Bug422Layer : public BugsTestBase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Bug422Layer);
|
||||
|
||||
virtual bool init() override;
|
||||
|
||||
void reset();
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
bool Bug458Layer::init()
|
||||
{
|
||||
if(BugsTestBaseLayer::init())
|
||||
if(BugsTestBase::init())
|
||||
{
|
||||
// ask director the the window size
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
|
||||
#include "../BugsTest.h"
|
||||
|
||||
class Bug458Layer : public BugsTestBaseLayer
|
||||
class Bug458Layer : public BugsTestBase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Bug458Layer);
|
||||
|
||||
virtual bool init() override;
|
||||
void selectAnswer(Ref* sender);
|
||||
};
|
||||
|
|
|
@ -17,7 +17,7 @@ Bug624Layer::~Bug624Layer()
|
|||
|
||||
bool Bug624Layer::init()
|
||||
{
|
||||
if(BugsTestBaseLayer::init())
|
||||
if(BugsTestBase::init())
|
||||
{
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
auto label = Label::createWithTTF("Layer1", "fonts/Marker Felt.ttf", 36.0f);
|
||||
|
@ -63,7 +63,7 @@ Bug624Layer2::~Bug624Layer2()
|
|||
|
||||
bool Bug624Layer2::init()
|
||||
{
|
||||
if(BugsTestBaseLayer::init())
|
||||
if(BugsTestBase::init())
|
||||
{
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
auto label = Label::createWithTTF("Layer2", "fonts/Marker Felt.ttf", 36.0f);
|
||||
|
|
|
@ -3,24 +3,24 @@
|
|||
|
||||
#include "BugsTest.h"
|
||||
|
||||
class Bug624Layer : public BugsTestBaseLayer
|
||||
class Bug624Layer : public BugsTestBase
|
||||
{
|
||||
public:
|
||||
virtual ~Bug624Layer();
|
||||
virtual bool init() override;
|
||||
void switchLayer(float dt);
|
||||
virtual void onAcceleration(Acceleration* acc, Event* event) override;
|
||||
virtual void onAcceleration(Acceleration* acc, Event* event);
|
||||
|
||||
CREATE_FUNC(Bug624Layer);
|
||||
};
|
||||
|
||||
class Bug624Layer2 : public BugsTestBaseLayer
|
||||
class Bug624Layer2 : public BugsTestBase
|
||||
{
|
||||
public:
|
||||
virtual ~Bug624Layer2();
|
||||
virtual bool init() override;
|
||||
void switchLayer(float dt);
|
||||
virtual void onAcceleration(Acceleration* acc, Event* event) override;
|
||||
virtual void onAcceleration(Acceleration* acc, Event* event);
|
||||
|
||||
CREATE_FUNC(Bug624Layer2);
|
||||
};
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
bool Bug886Layer::init()
|
||||
{
|
||||
if(BugsTestBaseLayer::init())
|
||||
if(BugsTestBase::init())
|
||||
{
|
||||
// ask director the the window size
|
||||
// auto size = [[Director sharedDirector] winSize];
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
|
||||
#include "BugsTest.h"
|
||||
|
||||
class Bug886Layer : public BugsTestBaseLayer
|
||||
class Bug886Layer : public BugsTestBase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Bug886Layer);
|
||||
|
||||
virtual bool init() override;
|
||||
};
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
bool Bug899Layer::init()
|
||||
{
|
||||
// Director::getInstance()->enableRetinaDisplay(true);
|
||||
if (BugsTestBaseLayer::init())
|
||||
if (BugsTestBase::init())
|
||||
{
|
||||
auto bg = Sprite::create("Images/bugs/RetinaDisplay.jpg");
|
||||
addChild(bg, 0);
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
|
||||
#include "BugsTest.h"
|
||||
|
||||
class Bug899Layer : public BugsTestBaseLayer
|
||||
class Bug899Layer : public BugsTestBase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Bug899Layer);
|
||||
|
||||
virtual bool init() override;
|
||||
};
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ bool Bug914Layer::init()
|
|||
{
|
||||
// always call "super" init
|
||||
// Apple recommends to re-assign "self" with the "super" return value
|
||||
if (BugsTestBaseLayer::init())
|
||||
if (BugsTestBase::init())
|
||||
{
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesBegan = CC_CALLBACK_2(Bug914Layer::onTouchesBegan, this);
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
|
||||
#include "BugsTest.h"
|
||||
|
||||
class Bug914Layer : public BugsTestBaseLayer
|
||||
class Bug914Layer : public BugsTestBase
|
||||
{
|
||||
public:
|
||||
static Scene* scene();
|
||||
virtual bool init() override;
|
||||
|
||||
void onTouchesMoved(const std::vector<Touch*>& touches, Event * event) override;
|
||||
void onTouchesBegan(const std::vector<Touch*>& touches, Event * event) override;
|
||||
void onTouchesMoved(const std::vector<Touch*>& touches, Event * event);
|
||||
void onTouchesBegan(const std::vector<Touch*>& touches, Event * event);
|
||||
void restart(Ref* sender);
|
||||
|
||||
CREATE_FUNC(Bug914Layer);
|
||||
|
|
|
@ -8,23 +8,9 @@
|
|||
|
||||
#include "Bug-Child.h"
|
||||
|
||||
Scene* BugChild::scene()
|
||||
{
|
||||
// 'scene' is an autorelease object.
|
||||
auto scene = Scene::create();
|
||||
// 'layer' is an autorelease object.
|
||||
auto layer = BugChild::create();
|
||||
|
||||
// add layer as a child to scene
|
||||
scene->addChild(layer);
|
||||
|
||||
// return the scene
|
||||
return scene;
|
||||
}
|
||||
|
||||
bool BugChild::init()
|
||||
{
|
||||
if (BugsTestBaseLayer::init())
|
||||
if (BugsTestBase::init())
|
||||
{
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
|
||||
|
|
|
@ -11,16 +11,15 @@
|
|||
|
||||
#include "BugsTest.h"
|
||||
|
||||
class BugChild : public BugsTestBaseLayer
|
||||
class BugChild : public BugsTestBase
|
||||
{
|
||||
public:
|
||||
static Scene* scene();
|
||||
CREATE_FUNC(BugChild);
|
||||
|
||||
virtual bool init() override;
|
||||
|
||||
void switchChild(Ref* sender);
|
||||
|
||||
CREATE_FUNC(BugChild);
|
||||
|
||||
protected:
|
||||
|
||||
Sprite* parent1;
|
||||
|
|
|
@ -10,139 +10,16 @@
|
|||
#include "Bug-1174.h"
|
||||
#include "Bug-Child.h"
|
||||
|
||||
#define TEST_BUG(__bug__) \
|
||||
{ \
|
||||
Scene* scene = Scene::create(); \
|
||||
Bug##__bug__##Layer* layer = new (std::nothrow) Bug##__bug__##Layer(); \
|
||||
layer->init(); \
|
||||
scene->addChild(layer); \
|
||||
Director::getInstance()->replaceScene(scene); \
|
||||
layer->autorelease(); \
|
||||
}
|
||||
|
||||
enum
|
||||
BugsTests::BugsTests()
|
||||
{
|
||||
LINE_SPACE = 40,
|
||||
kItemTagBasic = 5432,
|
||||
};
|
||||
|
||||
static Vec2 s_tCurPos = Vec2::ZERO;
|
||||
|
||||
struct {
|
||||
const char *test_name;
|
||||
std::function<void(Ref*)> callback;
|
||||
} g_bugs[] = {
|
||||
{ "Bug-Child", [](Ref* sender){Director::getInstance()->replaceScene(BugChild::scene());} },
|
||||
{ "Bug-350", [](Ref* sender){ TEST_BUG(350)} },
|
||||
{ "Bug-422", [](Ref* sender){ TEST_BUG(422)} },
|
||||
{ "Bug-458", [](Ref* sender){ TEST_BUG(458)} },
|
||||
{ "Bug-624", [](Ref* sender){ TEST_BUG(624)} },
|
||||
{ "Bug-886", [](Ref* sender){ TEST_BUG(886)} },
|
||||
{ "Bug-899", [](Ref* sender){ TEST_BUG(899)} },
|
||||
{ "Bug-914", [](Ref* sender){ TEST_BUG(914)} },
|
||||
{ "Bug-1159", [](Ref* sender){ TEST_BUG(1159)} },
|
||||
{ "Bug-1174", [](Ref* sender){ TEST_BUG(1174)} },
|
||||
};
|
||||
|
||||
static const int g_maxitems = sizeof(g_bugs) / sizeof(g_bugs[0]);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// BugsTestMainLayer
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
void BugsTestMainLayer::onEnter()
|
||||
{
|
||||
Layer::onEnter();
|
||||
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
_itmeMenu = Menu::create();
|
||||
MenuItemFont::setFontName("fonts/arial.ttf");
|
||||
MenuItemFont::setFontSize(24);
|
||||
for (int i = 0; i < g_maxitems; ++i)
|
||||
{
|
||||
auto pItem = MenuItemFont::create(g_bugs[i].test_name, g_bugs[i].callback);
|
||||
pItem->setPosition(s.width / 2, s.height - (i + 1) * LINE_SPACE);
|
||||
_itmeMenu->addChild(pItem, kItemTagBasic + i);
|
||||
}
|
||||
|
||||
_itmeMenu->setPosition(s_tCurPos);
|
||||
addChild(_itmeMenu);
|
||||
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesBegan = CC_CALLBACK_2(BugsTestMainLayer::onTouchesBegan, this);
|
||||
listener->onTouchesMoved = CC_CALLBACK_2(BugsTestMainLayer::onTouchesMoved, this);
|
||||
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||
}
|
||||
|
||||
void BugsTestMainLayer::onTouchesBegan(const std::vector<Touch*>& touches, Event *event)
|
||||
{
|
||||
_beginPos = touches[0]->getLocation();
|
||||
}
|
||||
|
||||
void BugsTestMainLayer::onTouchesMoved(const std::vector<Touch*>& touches, Event *event)
|
||||
{
|
||||
auto touchLocation = touches[0]->getLocation();
|
||||
float nMoveY = touchLocation.y - _beginPos.y;
|
||||
|
||||
auto curPos = _itmeMenu->getPosition();
|
||||
auto nextPos = Vec2(curPos.x, curPos.y + nMoveY);
|
||||
auto winSize = Director::getInstance()->getWinSize();
|
||||
if (nextPos.y < 0.0f)
|
||||
{
|
||||
_itmeMenu->setPosition(Vec2::ZERO);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextPos.y > ((g_maxitems + 1)* LINE_SPACE - winSize.height))
|
||||
{
|
||||
_itmeMenu->setPosition(0, ((g_maxitems + 1)* LINE_SPACE - winSize.height));
|
||||
return;
|
||||
}
|
||||
|
||||
_itmeMenu->setPosition(nextPos);
|
||||
_beginPos = touchLocation;
|
||||
s_tCurPos = nextPos;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// BugsTestBaseLayer
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
void BugsTestBaseLayer::onEnter()
|
||||
{
|
||||
Layer::onEnter();
|
||||
|
||||
MenuItemFont::setFontName("fonts/arial.ttf");
|
||||
MenuItemFont::setFontSize(24);
|
||||
auto pMainItem = MenuItemFont::create("Back", CC_CALLBACK_1(BugsTestBaseLayer::backCallback, this));
|
||||
pMainItem->setPosition(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25);
|
||||
auto menu = Menu::create(pMainItem, nullptr);
|
||||
menu->setPosition( Vec2::ZERO );
|
||||
addChild(menu);
|
||||
}
|
||||
|
||||
void BugsTestBaseLayer::backCallback(Ref* sender)
|
||||
{
|
||||
// Director::getInstance()->enableRetinaDisplay(false);
|
||||
auto scene = new (std::nothrow) BugsTestScene();
|
||||
scene->runThisTest();
|
||||
scene->autorelease();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// BugsTestScene
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
void BugsTestScene::runThisTest()
|
||||
{
|
||||
auto layer = new (std::nothrow) BugsTestMainLayer();
|
||||
addChild(layer);
|
||||
layer->release();
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
ADD_TEST_CASE(Bug350Layer);
|
||||
ADD_TEST_CASE(Bug422Layer);
|
||||
ADD_TEST_CASE(Bug458Layer);
|
||||
ADD_TEST_CASE(Bug624Layer);
|
||||
ADD_TEST_CASE(Bug886Layer);
|
||||
ADD_TEST_CASE(Bug899Layer);
|
||||
ADD_TEST_CASE(Bug914Layer);
|
||||
ADD_TEST_CASE(Bug1159Layer);
|
||||
ADD_TEST_CASE(Bug1174Layer);
|
||||
ADD_TEST_CASE(BugChild);
|
||||
}
|
||||
|
|
|
@ -1,32 +1,14 @@
|
|||
#ifndef __BUGS_TEST_H__
|
||||
#define __BUGS_TEST_H__
|
||||
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
|
||||
class BugsTestMainLayer : public Layer
|
||||
class BugsTestBase : public TestCase
|
||||
{
|
||||
public:
|
||||
virtual void onEnter() override;
|
||||
|
||||
void onTouchesBegan(const std::vector<Touch*>& touches, Event *event) override;
|
||||
void onTouchesMoved(const std::vector<Touch*>&touches, Event *event) override;
|
||||
|
||||
protected:
|
||||
Vec2 _beginPos;
|
||||
Menu* _itmeMenu;
|
||||
|
||||
};
|
||||
|
||||
class BugsTestBaseLayer : public Layer
|
||||
{
|
||||
public:
|
||||
virtual void onEnter() override;
|
||||
void backCallback(Ref* sender);
|
||||
};
|
||||
|
||||
class BugsTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
DEFINE_TEST_SUITE(BugsTests);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -32,82 +32,16 @@ enum
|
|||
IDC_RESTART
|
||||
};
|
||||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
static std::function<Layer*()> createFunctions[] =
|
||||
Camera3DTests::Camera3DTests()
|
||||
{
|
||||
CL(CameraRotationTest),
|
||||
CL(Camera3DTestDemo),
|
||||
CL(CameraCullingDemo),
|
||||
ADD_TEST_CASE(CameraRotationTest);
|
||||
ADD_TEST_CASE(Camera3DTestDemo);
|
||||
ADD_TEST_CASE(CameraCullingDemo);
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8)
|
||||
// 3DEffect use custom shader which is not supported on WP8 yet.
|
||||
CL(FogTestDemo),
|
||||
ADD_TEST_CASE(FogTestDemo);
|
||||
#endif
|
||||
CL(CameraArcBallDemo)
|
||||
};
|
||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||
|
||||
static Layer*nextTest()
|
||||
{
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_LAYER;
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
static Layer*backTest()
|
||||
{
|
||||
sceneIdx--;
|
||||
int total = MAX_LAYER;
|
||||
if( sceneIdx < 0 )
|
||||
sceneIdx += total;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
static Layer* restartTest()
|
||||
{
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
void Camera3DTestScene::runThisTest()
|
||||
{
|
||||
auto layer = nextTest();
|
||||
addChild(layer);
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// CameraBaseTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
void CameraBaseTest::restartCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) Camera3DTestScene();
|
||||
s->addChild(restartTest());
|
||||
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void CameraBaseTest::nextCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) Camera3DTestScene();
|
||||
s->addChild(nextTest());
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void CameraBaseTest::backCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) Camera3DTestScene();
|
||||
s->addChild(backTest());
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
ADD_TEST_CASE(CameraArcBallDemo);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
@ -220,12 +154,12 @@ std::string CameraRotationTest::subtitle() const
|
|||
|
||||
void CameraRotationTest::onEnter()
|
||||
{
|
||||
BaseTest::onEnter();
|
||||
CameraBaseTest::onEnter();
|
||||
}
|
||||
|
||||
void CameraRotationTest::onExit()
|
||||
{
|
||||
BaseTest::onExit();
|
||||
CameraBaseTest::onExit();
|
||||
}
|
||||
|
||||
void CameraRotationTest::update(float dt)
|
||||
|
@ -319,7 +253,7 @@ void Camera3DTestDemo::SwitchViewCallback(Ref* sender, CameraType cameraType)
|
|||
}
|
||||
void Camera3DTestDemo::onEnter()
|
||||
{
|
||||
BaseTest::onEnter();
|
||||
CameraBaseTest::onEnter();
|
||||
_sprite3D=nullptr;
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
|
@ -432,7 +366,7 @@ void Camera3DTestDemo::onEnter()
|
|||
}
|
||||
void Camera3DTestDemo::onExit()
|
||||
{
|
||||
BaseTest::onExit();
|
||||
CameraBaseTest::onExit();
|
||||
if (_camera)
|
||||
{
|
||||
_camera = nullptr;
|
||||
|
@ -785,16 +719,16 @@ std::string CameraCullingDemo::title() const
|
|||
|
||||
void CameraCullingDemo::onEnter()
|
||||
{
|
||||
BaseTest::onEnter();
|
||||
CameraBaseTest::onEnter();
|
||||
|
||||
schedule(schedule_selector(CameraCullingDemo::update), 0.0f);
|
||||
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesBegan = CC_CALLBACK_2(CameraCullingDemo::onTouchesBegan, this);
|
||||
listener->onTouchesMoved = CC_CALLBACK_2(CameraCullingDemo::onTouchesMoved, this);
|
||||
listener->onTouchesEnded = CC_CALLBACK_2(CameraCullingDemo::onTouchesEnded, this);
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||
/*auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesBegan = CC_CALLBACK_2(Camera3DTestDemo::onTouchesBegan, this);
|
||||
listener->onTouchesMoved = CC_CALLBACK_2(Camera3DTestDemo::onTouchesMoved, this);
|
||||
listener->onTouchesEnded = CC_CALLBACK_2(Camera3DTestDemo::onTouchesEnded, this);
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);*/
|
||||
auto layer3D=Layer::create();
|
||||
addChild(layer3D,0);
|
||||
_layer3D=layer3D;
|
||||
|
@ -847,7 +781,7 @@ void CameraCullingDemo::onEnter()
|
|||
|
||||
void CameraCullingDemo::onExit()
|
||||
{
|
||||
BaseTest::onExit();
|
||||
CameraBaseTest::onExit();
|
||||
if (_cameraFirst)
|
||||
{
|
||||
_cameraFirst = nullptr;
|
||||
|
@ -1070,7 +1004,7 @@ std::string CameraArcBallDemo::title() const
|
|||
|
||||
void CameraArcBallDemo::onEnter()
|
||||
{
|
||||
BaseTest::onEnter();
|
||||
CameraBaseTest::onEnter();
|
||||
_rotationQuat.set(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
schedule(schedule_selector(CameraArcBallDemo::update), 0.0f);
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
|
@ -1142,7 +1076,7 @@ void CameraArcBallDemo::onEnter()
|
|||
|
||||
void CameraArcBallDemo::onExit()
|
||||
{
|
||||
BaseTest::onExit();
|
||||
CameraBaseTest::onExit();
|
||||
if (_camera)
|
||||
{
|
||||
_camera = nullptr;
|
||||
|
@ -1287,7 +1221,7 @@ std::string FogTestDemo::title() const
|
|||
|
||||
void FogTestDemo::onEnter()
|
||||
{
|
||||
BaseTest::onEnter();
|
||||
CameraBaseTest::onEnter();
|
||||
schedule(schedule_selector(FogTestDemo::update), 0.0f);
|
||||
Director::getInstance()->setClearColor(Color4F(0.5,0.5,0.5,1));
|
||||
|
||||
|
@ -1437,7 +1371,7 @@ void FogTestDemo::switchTypeCallback(Ref* sender,int type)
|
|||
|
||||
void FogTestDemo::onExit()
|
||||
{
|
||||
BaseTest::onExit();
|
||||
CameraBaseTest::onExit();
|
||||
Director::getInstance()->setClearColor(Color4F(0,0,0,1));
|
||||
if (_camera)
|
||||
{
|
||||
|
|
|
@ -25,7 +25,6 @@ THE SOFTWARE.
|
|||
#ifndef _CAMERA3D_TEST_H_
|
||||
#define _CAMERA3D_TEST_H_
|
||||
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
#include "../Sprite3DTest/DrawNode3D.h"
|
||||
#include <string>
|
||||
|
@ -59,18 +58,11 @@ enum class OperateCamType
|
|||
RotateCamera=1,
|
||||
};
|
||||
|
||||
class Camera3DTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
DEFINE_TEST_SUITE(Camera3DTests);
|
||||
|
||||
class CameraBaseTest : public BaseTest
|
||||
class CameraBaseTest : public TestCase
|
||||
{
|
||||
public:
|
||||
void restartCallback(Ref* sender) override;
|
||||
void nextCallback(Ref* sender) override;
|
||||
void backCallback(Ref* sender) override;
|
||||
|
||||
protected:
|
||||
BillBoard* bill1;
|
||||
|
@ -114,9 +106,11 @@ public:
|
|||
// overrides
|
||||
virtual std::string title() const override;
|
||||
void addNewSpriteWithCoords(Vec3 p,std::string fileName,bool playAnimation=false,float scale=1.0f,bool bindCamera=false);
|
||||
void onTouchesBegan(const std::vector<Touch*>& touches, cocos2d::Event *event) override;
|
||||
void onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Event *event) override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, cocos2d::Event *event) override;
|
||||
|
||||
void onTouchesBegan(const std::vector<Touch*>& touches, cocos2d::Event *event);
|
||||
void onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Event *event);
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, cocos2d::Event *event);
|
||||
|
||||
void scaleCameraCallback(Ref* sender,float value);
|
||||
void rotateCameraCallback(Ref* sender,float value);
|
||||
void SwitchViewCallback(Ref* sender,CameraType cameraType);
|
||||
|
@ -243,7 +237,7 @@ public:
|
|||
// overrides
|
||||
virtual std::string title() const override;
|
||||
|
||||
void onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Event *event) override;
|
||||
void onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Event *event);
|
||||
|
||||
void switchTypeCallback(Ref* sender,int type);
|
||||
|
||||
|
|
|
@ -17,17 +17,17 @@ enum {
|
|||
|
||||
// callback to remove Shapes from the Space
|
||||
|
||||
ChipmunkTestLayer::ChipmunkTestLayer()
|
||||
ChipmunkTest::ChipmunkTest()
|
||||
{
|
||||
#if CC_ENABLE_CHIPMUNK_INTEGRATION
|
||||
// enable events
|
||||
|
||||
auto touchListener = EventListenerTouchAllAtOnce::create();
|
||||
touchListener->onTouchesEnded = CC_CALLBACK_2(ChipmunkTestLayer::onTouchesEnded, this);
|
||||
touchListener->onTouchesEnded = CC_CALLBACK_2(ChipmunkTest::onTouchesEnded, this);
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
|
||||
|
||||
Device::setAccelerometerEnabled(true);
|
||||
auto accListener = EventListenerAcceleration::create(CC_CALLBACK_2(ChipmunkTestLayer::onAcceleration, this));
|
||||
auto accListener = EventListenerAcceleration::create(CC_CALLBACK_2(ChipmunkTest::onAcceleration, this));
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(accListener, this);
|
||||
|
||||
// title
|
||||
|
@ -56,7 +56,7 @@ ChipmunkTestLayer::ChipmunkTestLayer()
|
|||
|
||||
// menu for debug layer
|
||||
MenuItemFont::setFontSize(18);
|
||||
auto item = MenuItemFont::create("Toggle debug", CC_CALLBACK_1(ChipmunkTestLayer::toggleDebugCallback, this));
|
||||
auto item = MenuItemFont::create("Toggle debug", CC_CALLBACK_1(ChipmunkTest::toggleDebugCallback, this));
|
||||
|
||||
auto menu = Menu::create(item, nullptr);
|
||||
this->addChild(menu);
|
||||
|
@ -76,14 +76,14 @@ ChipmunkTestLayer::ChipmunkTestLayer()
|
|||
|
||||
}
|
||||
|
||||
void ChipmunkTestLayer::toggleDebugCallback(Ref* sender)
|
||||
void ChipmunkTest::toggleDebugCallback(Ref* sender)
|
||||
{
|
||||
#if CC_ENABLE_CHIPMUNK_INTEGRATION
|
||||
_debugLayer->setVisible(! _debugLayer->isVisible());
|
||||
#endif
|
||||
}
|
||||
|
||||
ChipmunkTestLayer::~ChipmunkTestLayer()
|
||||
ChipmunkTest::~ChipmunkTest()
|
||||
{
|
||||
#if CC_ENABLE_CHIPMUNK_INTEGRATION
|
||||
// manually Free rogue shapes
|
||||
|
@ -97,7 +97,7 @@ ChipmunkTestLayer::~ChipmunkTestLayer()
|
|||
#endif
|
||||
}
|
||||
|
||||
void ChipmunkTestLayer::initPhysics()
|
||||
void ChipmunkTest::initPhysics()
|
||||
{
|
||||
#if CC_ENABLE_CHIPMUNK_INTEGRATION
|
||||
// init chipmunk
|
||||
|
@ -143,7 +143,7 @@ void ChipmunkTestLayer::initPhysics()
|
|||
#endif
|
||||
}
|
||||
|
||||
void ChipmunkTestLayer::update(float delta)
|
||||
void ChipmunkTest::update(float delta)
|
||||
{
|
||||
// Should use a fixed size step based on the animation interval.
|
||||
int steps = 2;
|
||||
|
@ -154,9 +154,9 @@ void ChipmunkTestLayer::update(float delta)
|
|||
}
|
||||
}
|
||||
|
||||
void ChipmunkTestLayer::createResetButton()
|
||||
void ChipmunkTest::createResetButton()
|
||||
{
|
||||
auto reset = MenuItemImage::create("Images/r1.png", "Images/r2.png", CC_CALLBACK_1(ChipmunkTestLayer::reset, this));
|
||||
auto reset = MenuItemImage::create("Images/r1.png", "Images/r2.png", CC_CALLBACK_1(ChipmunkTest::reset, this));
|
||||
|
||||
auto menu = Menu::create(reset, nullptr);
|
||||
|
||||
|
@ -164,17 +164,12 @@ void ChipmunkTestLayer::createResetButton()
|
|||
this->addChild(menu, -1);
|
||||
}
|
||||
|
||||
void ChipmunkTestLayer::reset(Ref* sender)
|
||||
void ChipmunkTest::reset(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ChipmunkAccelTouchTestScene();
|
||||
auto child = new (std::nothrow) ChipmunkTestLayer();
|
||||
s->addChild(child);
|
||||
child->release();
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
getTestSuite()->restartCurrTest();
|
||||
}
|
||||
|
||||
void ChipmunkTestLayer::addNewSpriteAtPosition(cocos2d::Vec2 pos)
|
||||
void ChipmunkTest::addNewSpriteAtPosition(cocos2d::Vec2 pos)
|
||||
{
|
||||
#if CC_ENABLE_CHIPMUNK_INTEGRATION
|
||||
int posx, posy;
|
||||
|
@ -213,12 +208,12 @@ void ChipmunkTestLayer::addNewSpriteAtPosition(cocos2d::Vec2 pos)
|
|||
#endif
|
||||
}
|
||||
|
||||
void ChipmunkTestLayer::onEnter()
|
||||
void ChipmunkTest::onEnter()
|
||||
{
|
||||
Layer::onEnter();
|
||||
TestCase::onEnter();
|
||||
}
|
||||
|
||||
void ChipmunkTestLayer::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
||||
void ChipmunkTest::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
||||
{
|
||||
//Add a new body/atlas sprite at the touched location
|
||||
|
||||
|
@ -230,7 +225,7 @@ void ChipmunkTestLayer::onTouchesEnded(const std::vector<Touch*>& touches, Event
|
|||
}
|
||||
}
|
||||
|
||||
void ChipmunkTestLayer::onAcceleration(Acceleration* acc, Event* event)
|
||||
void ChipmunkTest::onAcceleration(Acceleration* acc, Event* event)
|
||||
{
|
||||
static float prevX=0, prevY=0;
|
||||
|
||||
|
@ -247,12 +242,8 @@ void ChipmunkTestLayer::onAcceleration(Acceleration* acc, Event* event)
|
|||
_space->gravity = cpv(v.x, v.y);
|
||||
}
|
||||
|
||||
void ChipmunkAccelTouchTestScene::runThisTest()
|
||||
ChipmunkTests::ChipmunkTests()
|
||||
{
|
||||
auto layer = new (std::nothrow) ChipmunkTestLayer();
|
||||
addChild(layer);
|
||||
layer->release();
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
ADD_TEST_CASE(ChipmunkTest);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,16 +6,18 @@
|
|||
|
||||
#include "cocos2d.h"
|
||||
#include "chipmunk.h"
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
#include "extensions/cocos-ext.h"
|
||||
|
||||
USING_NS_CC_EXT;
|
||||
|
||||
class ChipmunkTestLayer : public Layer
|
||||
class ChipmunkTest : public TestCase
|
||||
{
|
||||
public:
|
||||
ChipmunkTestLayer();
|
||||
~ChipmunkTestLayer();
|
||||
CREATE_FUNC(ChipmunkTest);
|
||||
|
||||
ChipmunkTest();
|
||||
~ChipmunkTest();
|
||||
void onEnter() override;
|
||||
void initPhysics();
|
||||
void createResetButton();
|
||||
|
@ -24,8 +26,8 @@ public:
|
|||
void addNewSpriteAtPosition(cocos2d::Vec2 p);
|
||||
void update(float dt) override;
|
||||
void toggleDebugCallback(Ref* sender);
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
|
||||
virtual void onAcceleration(Acceleration* acc, Event* event) override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||
virtual void onAcceleration(Acceleration* acc, Event* event);
|
||||
|
||||
private:
|
||||
Texture2D* _spriteTexture; // weak ref
|
||||
|
@ -36,10 +38,6 @@ private:
|
|||
cpShape* _walls[4];
|
||||
};
|
||||
|
||||
class ChipmunkAccelTouchTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
DEFINE_TEST_SUITE(ChipmunkTests);
|
||||
|
||||
#endif /* __CHIPMUNKACCELTOUCHTEST_H__ */
|
||||
|
|
|
@ -6,20 +6,16 @@ enum
|
|||
kTagSprite = 1,
|
||||
};
|
||||
|
||||
void ClickAndMoveTestScene::runThisTest()
|
||||
ClickAndMoveTest::ClickAndMoveTest()
|
||||
{
|
||||
auto layer = new (std::nothrow) MainLayer();
|
||||
layer->autorelease();
|
||||
|
||||
addChild(layer);
|
||||
Director::getInstance()->replaceScene(this);
|
||||
ADD_TEST_CASE(ClickAndMoveTestCase);
|
||||
}
|
||||
|
||||
MainLayer::MainLayer()
|
||||
ClickAndMoveTestCase::ClickAndMoveTestCase()
|
||||
{
|
||||
auto listener = EventListenerTouchOneByOne::create();
|
||||
listener->onTouchBegan = CC_CALLBACK_2(MainLayer::onTouchBegan, this);
|
||||
listener->onTouchEnded = CC_CALLBACK_2(MainLayer::onTouchEnded, this);
|
||||
listener->onTouchBegan = CC_CALLBACK_2(ClickAndMoveTestCase::onTouchBegan, this);
|
||||
listener->onTouchEnded = CC_CALLBACK_2(ClickAndMoveTestCase::onTouchEnded, this);
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||
|
||||
auto sprite = Sprite::create(s_pathGrossini);
|
||||
|
@ -40,12 +36,12 @@ MainLayer::MainLayer()
|
|||
));
|
||||
}
|
||||
|
||||
bool MainLayer::onTouchBegan(Touch* touch, Event *event)
|
||||
bool ClickAndMoveTestCase::onTouchBegan(Touch* touch, Event *event)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainLayer::onTouchEnded(Touch* touch, Event *event)
|
||||
void ClickAndMoveTestCase::onTouchEnded(Touch* touch, Event *event)
|
||||
{
|
||||
auto location = touch->getLocation();
|
||||
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
#ifndef _CLICK_AND_MOVE_TEST_H_
|
||||
#define _CLICK_AND_MOVE_TEST_H_
|
||||
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
|
||||
class ClickAndMoveTestScene : public TestScene
|
||||
DEFINE_TEST_SUITE(ClickAndMoveTest);
|
||||
|
||||
class ClickAndMoveTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
CREATE_FUNC(ClickAndMoveTestCase);
|
||||
|
||||
class MainLayer : public Layer
|
||||
{
|
||||
public:
|
||||
MainLayer();
|
||||
ClickAndMoveTestCase();
|
||||
bool onTouchBegan(Touch* touch, Event *event);
|
||||
void onTouchEnded(Touch* touch, Event *event);
|
||||
};
|
||||
|
|
|
@ -17,64 +17,33 @@ enum {
|
|||
kTagContentNode = 102,
|
||||
};
|
||||
|
||||
static std::function<Layer*()> createFunctions[] = {
|
||||
CL(ScrollViewDemo),
|
||||
CL(HoleDemo),
|
||||
CL(ShapeTest),
|
||||
CL(ShapeInvertedTest),
|
||||
CL(SpriteTest),
|
||||
CL(SpriteNoAlphaTest),
|
||||
CL(SpriteInvertedTest),
|
||||
CL(NestedTest),
|
||||
CL(RawStencilBufferTest),
|
||||
CL(RawStencilBufferTest2),
|
||||
CL(RawStencilBufferTest3),
|
||||
CL(RawStencilBufferTest4),
|
||||
CL(RawStencilBufferTest5),
|
||||
CL(RawStencilBufferTest6),
|
||||
CL(ClippingToRenderTextureTest),
|
||||
CL(ClippingRectangleNodeTest),
|
||||
};
|
||||
|
||||
static int sceneIdx=-1;
|
||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||
|
||||
static Layer* nextAction()
|
||||
ClippingNodeTests::ClippingNodeTests()
|
||||
{
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_LAYER;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
|
||||
return layer;
|
||||
ADD_TEST_CASE(ScrollViewDemo);
|
||||
ADD_TEST_CASE(HoleDemo);
|
||||
ADD_TEST_CASE(ShapeTest);
|
||||
ADD_TEST_CASE(ShapeInvertedTest);
|
||||
ADD_TEST_CASE(SpriteTest);
|
||||
ADD_TEST_CASE(SpriteNoAlphaTest);
|
||||
ADD_TEST_CASE(SpriteInvertedTest);
|
||||
ADD_TEST_CASE(NestedTest);
|
||||
ADD_TEST_CASE(RawStencilBufferTest);
|
||||
ADD_TEST_CASE(RawStencilBufferTest2);
|
||||
ADD_TEST_CASE(RawStencilBufferTest3);
|
||||
ADD_TEST_CASE(RawStencilBufferTest4);
|
||||
ADD_TEST_CASE(RawStencilBufferTest5);
|
||||
ADD_TEST_CASE(RawStencilBufferTest6);
|
||||
ADD_TEST_CASE(ClippingToRenderTextureTest);
|
||||
ADD_TEST_CASE(ClippingRectangleNodeTest);
|
||||
}
|
||||
|
||||
static Layer* backAction()
|
||||
{
|
||||
sceneIdx--;
|
||||
int total = MAX_LAYER;
|
||||
if( sceneIdx < 0 )
|
||||
sceneIdx += total;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
static Layer* restartAction()
|
||||
{
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
//// Demo examples start here
|
||||
|
||||
//@implementation BaseClippingNodeTest
|
||||
|
||||
bool BaseClippingNodeTest::init()
|
||||
{
|
||||
if (BaseTest::init()) {
|
||||
if (TestCase::init()) {
|
||||
|
||||
auto background = Sprite::create(s_back3);
|
||||
background->setAnchorPoint( Vec2::ZERO );
|
||||
|
@ -97,35 +66,6 @@ std::string BaseClippingNodeTest::title() const
|
|||
return "Clipping Demo";
|
||||
}
|
||||
|
||||
std::string BaseClippingNodeTest::subtitle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
void BaseClippingNodeTest::restartCallback(Ref* sender)
|
||||
{
|
||||
Scene *s = new (std::nothrow) ClippingNodeTestScene();
|
||||
s->addChild(restartAction());
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void BaseClippingNodeTest::nextCallback(Ref* sender)
|
||||
{
|
||||
Scene *s = new (std::nothrow) ClippingNodeTestScene();
|
||||
s->addChild(nextAction());
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void BaseClippingNodeTest::backCallback(Ref* sender)
|
||||
{
|
||||
Scene *s = new (std::nothrow) ClippingNodeTestScene();
|
||||
s->addChild(backAction());
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void BaseClippingNodeTest::setup()
|
||||
{
|
||||
|
||||
|
@ -1128,13 +1068,3 @@ void ClippingRectangleNodeTest::setup()
|
|||
content->setPosition(this->getContentSize().width / 2, this->getContentSize().height / 2);
|
||||
clipper->addChild(content);
|
||||
}
|
||||
|
||||
|
||||
// main entry point
|
||||
|
||||
void ClippingNodeTestScene::runThisTest()
|
||||
{
|
||||
auto layer = nextAction();
|
||||
addChild(layer);
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
#ifndef __CLIPPINGNODETEST_H__
|
||||
#define __CLIPPINGNODETEST_H__
|
||||
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
#include <list>
|
||||
|
||||
class BaseClippingNodeTest : public BaseTest
|
||||
DEFINE_TEST_SUITE(ClippingNodeTests);
|
||||
|
||||
class BaseClippingNodeTest : public TestCase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(BaseClippingNodeTest);
|
||||
|
@ -15,12 +16,7 @@ public:
|
|||
virtual bool init() override;
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void setup();
|
||||
|
||||
void backCallback(Ref* sender) override;
|
||||
void nextCallback(Ref* sender) override;
|
||||
void restartCallback(Ref* sender) override;
|
||||
};
|
||||
|
||||
class BasicTest : public BaseClippingNodeTest
|
||||
|
@ -118,7 +114,7 @@ public:
|
|||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
void pokeHoleAtPoint(Vec2 point);
|
||||
void onTouchesBegan(const std::vector<Touch*>& touches, Event *event) override;
|
||||
void onTouchesBegan(const std::vector<Touch*>& touches, Event *event);
|
||||
private:
|
||||
ClippingNode* _outerClipper;
|
||||
Node* _holes;
|
||||
|
@ -133,9 +129,9 @@ public:
|
|||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void setup() override;
|
||||
void onTouchesBegan(const std::vector<Touch*>& touches, Event *event) override;
|
||||
void onTouchesMoved(const std::vector<Touch*>& touches, Event *event) override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event *event) override;
|
||||
void onTouchesBegan(const std::vector<Touch*>& touches, Event *event);
|
||||
void onTouchesMoved(const std::vector<Touch*>& touches, Event *event);
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event *event);
|
||||
private:
|
||||
bool _scrolling;
|
||||
Vec2 _lastPoint;
|
||||
|
@ -254,13 +250,4 @@ public:
|
|||
virtual void setup() override;
|
||||
};
|
||||
|
||||
|
||||
class ClippingNodeTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(ClippingNodeTestScene);
|
||||
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
#endif //__CLIPPINGNODETEST_H__
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "CocosDenshionTest.h"
|
||||
#include "cocos2d.h"
|
||||
#include "extensions/GUI/CCControlExtension/CCControlSlider.h"
|
||||
#include "audio/include/SimpleAudioEngine.h"
|
||||
|
||||
// android effect only support ogg
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
|
@ -248,7 +249,7 @@ CocosDenshionTest::~CocosDenshionTest()
|
|||
|
||||
void CocosDenshionTest::onExit()
|
||||
{
|
||||
Layer::onExit();
|
||||
TestCase::onExit();
|
||||
|
||||
SimpleAudioEngine::end();
|
||||
}
|
||||
|
@ -416,11 +417,7 @@ void CocosDenshionTest::updateVolumes(float)
|
|||
}
|
||||
}
|
||||
|
||||
void CocosDenshionTestScene::runThisTest()
|
||||
CocosDenshionTests::CocosDenshionTests()
|
||||
{
|
||||
auto layer = new (std::nothrow) CocosDenshionTest();
|
||||
addChild(layer);
|
||||
layer->autorelease();
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
ADD_TEST_CASE(CocosDenshionTest);
|
||||
}
|
|
@ -1,13 +1,17 @@
|
|||
#ifndef __COCOS_DENSHION_TEST__
|
||||
#define __COCOS_DENSHION_TEST__
|
||||
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
|
||||
class AudioSlider;
|
||||
|
||||
class CocosDenshionTest : public Layer
|
||||
DEFINE_TEST_SUITE(CocosDenshionTests);
|
||||
|
||||
class CocosDenshionTest : public TestCase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(CocosDenshionTest);
|
||||
|
||||
CocosDenshionTest(void);
|
||||
~CocosDenshionTest(void);
|
||||
|
||||
|
@ -30,10 +34,4 @@ private:
|
|||
AudioSlider *_sliderMusicVolume;
|
||||
};
|
||||
|
||||
class CocosDenshionTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
#endif //__COCOS_DENSHION_TEST__
|
||||
|
|
|
@ -33,43 +33,12 @@ enum
|
|||
IDC_RESTART
|
||||
};
|
||||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
|
||||
static std::function<Layer*()> createFunctions[] =
|
||||
CocosStudio3DTests::CocosStudio3DTests()
|
||||
{
|
||||
CL(CSNode3DTest),
|
||||
CL(CSSprite3DTest),
|
||||
CL(CSUserCameraTest),
|
||||
CL(CSParticle3DTest)
|
||||
};
|
||||
|
||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||
|
||||
static Layer* nextCocosStudio3DTestAction()
|
||||
{
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_LAYER;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
static Layer* backCocosStudio3DTestAction()
|
||||
{
|
||||
sceneIdx--;
|
||||
int total = MAX_LAYER;
|
||||
if( sceneIdx < 0 )
|
||||
sceneIdx += total;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
static Layer* restartCocosStudio3DTestAction()
|
||||
{
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
ADD_TEST_CASE(CSNode3DTest);
|
||||
ADD_TEST_CASE(CSSprite3DTest);
|
||||
ADD_TEST_CASE(CSUserCameraTest);
|
||||
ADD_TEST_CASE(CSParticle3DTest);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
@ -79,7 +48,6 @@ static Layer* restartCocosStudio3DTestAction()
|
|||
//------------------------------------------------------------------
|
||||
|
||||
CocosStudio3DTestDemo::CocosStudio3DTestDemo(void)
|
||||
: BaseTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -92,46 +60,10 @@ std::string CocosStudio3DTestDemo::title() const
|
|||
return "No title";
|
||||
}
|
||||
|
||||
std::string CocosStudio3DTestDemo::subtitle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
void CocosStudio3DTestDemo::onEnter()
|
||||
{
|
||||
BaseTest::onEnter();
|
||||
}
|
||||
|
||||
void CocosStudio3DTestDemo::onExit()
|
||||
{
|
||||
cocostudio::destroyCocosStudio();
|
||||
|
||||
BaseTest::onExit();
|
||||
}
|
||||
|
||||
void CocosStudio3DTestDemo::restartCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) CS3DTestScene();
|
||||
s->addChild(restartCocosStudio3DTestAction());
|
||||
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void CocosStudio3DTestDemo::nextCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) CS3DTestScene();
|
||||
s->addChild( nextCocosStudio3DTestAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void CocosStudio3DTestDemo::backCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) CS3DTestScene();
|
||||
s->addChild( backCocosStudio3DTestAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
TestCase::onExit();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
@ -151,11 +83,6 @@ std::string CSNode3DTest::title() const
|
|||
return "Node3DReader Test";
|
||||
}
|
||||
|
||||
std::string CSNode3DTest::subtitle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// CSSprite3DTest
|
||||
|
@ -180,11 +107,6 @@ std::string CSSprite3DTest::title() const
|
|||
return "Sprite3DReader Test";
|
||||
}
|
||||
|
||||
std::string CSSprite3DTest::subtitle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// CSUserCameraTest
|
||||
|
@ -207,11 +129,6 @@ std::string CSUserCameraTest::title() const
|
|||
return "UserCameraReader Test";
|
||||
}
|
||||
|
||||
std::string CSUserCameraTest::subtitle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// CSParticle3DTest
|
||||
|
@ -228,27 +145,3 @@ std::string CSParticle3DTest::title() const
|
|||
{
|
||||
return "Particle3DReader Test";
|
||||
}
|
||||
|
||||
std::string CSParticle3DTest::subtitle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// CS3DTestScene
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
void CS3DTestScene::runThisTest()
|
||||
{
|
||||
auto layer = nextCocosStudio3DTestAction();
|
||||
addChild(layer);
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
||||
CS3DTestScene::CS3DTestScene()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -29,24 +29,16 @@
|
|||
#include "../BaseTest.h"
|
||||
#include <string>
|
||||
|
||||
namespace cocos2d {
|
||||
DEFINE_TEST_SUITE(CocosStudio3DTests);
|
||||
|
||||
}
|
||||
|
||||
class CocosStudio3DTestDemo : public BaseTest
|
||||
class CocosStudio3DTestDemo : public TestCase
|
||||
{
|
||||
public:
|
||||
CocosStudio3DTestDemo(void);
|
||||
virtual ~CocosStudio3DTestDemo(void);
|
||||
|
||||
void restartCallback(Ref* sender) override;
|
||||
void nextCallback(Ref* sender) override;
|
||||
void backCallback(Ref* sender) override;
|
||||
|
||||
// overrides
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
};
|
||||
|
||||
|
@ -56,7 +48,6 @@ public:
|
|||
CREATE_FUNC(CSNode3DTest);
|
||||
CSNode3DTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class CSSprite3DTest : public CocosStudio3DTestDemo
|
||||
|
@ -65,7 +56,6 @@ public:
|
|||
CREATE_FUNC(CSSprite3DTest);
|
||||
CSSprite3DTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class CSUserCameraTest : public CocosStudio3DTestDemo
|
||||
|
@ -74,7 +64,6 @@ public:
|
|||
CREATE_FUNC(CSUserCameraTest);
|
||||
CSUserCameraTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class CSParticle3DTest : public CocosStudio3DTestDemo
|
||||
|
@ -83,15 +72,7 @@ public:
|
|||
CREATE_FUNC(CSParticle3DTest);
|
||||
CSParticle3DTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
|
||||
class CS3DTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
CS3DTestScene();
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,96 +3,20 @@
|
|||
#include "../testResource.h"
|
||||
#include "cocos2d.h"
|
||||
|
||||
static std::function<Layer*()> createFunctions[] = {
|
||||
CL(ConfigurationLoadConfig),
|
||||
CL(ConfigurationQuery),
|
||||
CL(ConfigurationInvalid),
|
||||
CL(ConfigurationDefault),
|
||||
CL(ConfigurationSet)
|
||||
};
|
||||
|
||||
static int sceneIdx=-1;
|
||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||
|
||||
static Layer* nextAction()
|
||||
ConfigurationTests::ConfigurationTests()
|
||||
{
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_LAYER;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
ADD_TEST_CASE(ConfigurationLoadConfig);
|
||||
ADD_TEST_CASE(ConfigurationQuery);
|
||||
ADD_TEST_CASE(ConfigurationInvalid);
|
||||
ADD_TEST_CASE(ConfigurationDefault);
|
||||
ADD_TEST_CASE(ConfigurationSet);
|
||||
}
|
||||
|
||||
static Layer* backAction()
|
||||
{
|
||||
sceneIdx--;
|
||||
int total = MAX_LAYER;
|
||||
if( sceneIdx < 0 )
|
||||
sceneIdx += total;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
static Layer* restartAction()
|
||||
{
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
void ConfigurationTestScene::runThisTest()
|
||||
{
|
||||
sceneIdx = -1;
|
||||
addChild(nextAction());
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
||||
|
||||
std::string ConfigurationBase::title() const
|
||||
{
|
||||
return "Configuration Test";
|
||||
}
|
||||
|
||||
std::string ConfigurationBase::subtitle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
void ConfigurationBase::onEnter()
|
||||
{
|
||||
BaseTest::onEnter();
|
||||
}
|
||||
|
||||
void ConfigurationBase::onExit()
|
||||
{
|
||||
BaseTest::onExit();
|
||||
}
|
||||
|
||||
void ConfigurationBase::restartCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ConfigurationTestScene();
|
||||
s->addChild( restartAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void ConfigurationBase::nextCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ConfigurationTestScene();
|
||||
s->addChild( nextAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void ConfigurationBase::backCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ConfigurationTestScene();
|
||||
s->addChild( backAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// ConfigurationLoadConfig
|
||||
|
|
|
@ -6,30 +6,14 @@
|
|||
|
||||
USING_NS_CC;
|
||||
|
||||
DEFINE_TEST_SUITE(ConfigurationTests);
|
||||
|
||||
// the class inherit from TestScene
|
||||
// every Scene each test used must inherit from TestScene,
|
||||
// make sure the test have the menu item for back to main menu
|
||||
class ConfigurationTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
class ConfigurationBase : public BaseTest
|
||||
class ConfigurationBase : public TestCase
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void restartCallback(Ref* sender) override;
|
||||
void nextCallback(Ref* sender) override;
|
||||
void backCallback(Ref* sender) override;
|
||||
};
|
||||
|
||||
class ConfigurationLoadConfig : public ConfigurationBase
|
||||
|
|
|
@ -47,43 +47,12 @@
|
|||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
static std::function<Layer*()> createFunctions[] =
|
||||
ConsoleTests::ConsoleTests()
|
||||
{
|
||||
CL(ConsoleCustomCommand),
|
||||
CL(ConsoleUploadFile),
|
||||
};
|
||||
|
||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||
|
||||
Layer* nextConsoleTest()
|
||||
{
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_LAYER;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
ADD_TEST_CASE(ConsoleCustomCommand);
|
||||
ADD_TEST_CASE(ConsoleUploadFile);
|
||||
}
|
||||
|
||||
Layer* backConsoleTest()
|
||||
{
|
||||
sceneIdx--;
|
||||
int total = MAX_LAYER;
|
||||
if( sceneIdx < 0 )
|
||||
sceneIdx += total;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
Layer* restartConsoleTest()
|
||||
{
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
return layer;
|
||||
}
|
||||
|
||||
|
||||
BaseTestConsole::BaseTestConsole()
|
||||
{
|
||||
}
|
||||
|
@ -97,44 +66,6 @@ std::string BaseTestConsole::title() const
|
|||
return "No title";
|
||||
}
|
||||
|
||||
void BaseTestConsole::onEnter()
|
||||
{
|
||||
BaseTest::onEnter();
|
||||
}
|
||||
|
||||
void BaseTestConsole::restartCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ConsoleTestScene();
|
||||
s->addChild(restartConsoleTest());
|
||||
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void BaseTestConsole::nextCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ConsoleTestScene();
|
||||
s->addChild( nextConsoleTest() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void BaseTestConsole::backCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) ConsoleTestScene();
|
||||
s->addChild( backConsoleTest() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void ConsoleTestScene::runThisTest()
|
||||
{
|
||||
auto layer = nextConsoleTest();
|
||||
addChild(layer);
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// ConsoleCustomCommand
|
||||
|
|
|
@ -25,24 +25,19 @@
|
|||
#ifndef _CONSOLE_TEST_H_
|
||||
#define _CONSOLE_TEST_H_
|
||||
|
||||
////----#include "cocos2d.h"
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
class BaseTestConsole : public BaseTest
|
||||
DEFINE_TEST_SUITE(ConsoleTests);
|
||||
|
||||
class BaseTestConsole : public TestCase
|
||||
{
|
||||
public:
|
||||
BaseTestConsole();
|
||||
~BaseTestConsole();
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual void onEnter() override;
|
||||
|
||||
virtual void restartCallback(Ref* sender) override;
|
||||
virtual void nextCallback(Ref* sender) override;
|
||||
virtual void backCallback(Ref* sender) override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -85,10 +80,4 @@ private:
|
|||
CC_DISALLOW_COPY_AND_ASSIGN(ConsoleUploadFile);
|
||||
};
|
||||
|
||||
class ConsoleTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
#endif // _CONSOLE_TEST_H_
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
#include "stdlib.h"
|
||||
#include "curl/curl.h"
|
||||
|
||||
CurlTests::CurlTests()
|
||||
{
|
||||
ADD_TEST_CASE(CurlTest);
|
||||
}
|
||||
|
||||
CurlTest::CurlTest()
|
||||
{
|
||||
auto label = Label::createWithTTF("Curl Test", "fonts/arial.ttf", 28);
|
||||
|
@ -93,12 +98,3 @@ CurlTest::~CurlTest()
|
|||
{
|
||||
_label->release();
|
||||
}
|
||||
|
||||
void CurlTestScene::runThisTest()
|
||||
{
|
||||
auto layer = new (std::nothrow) CurlTest();
|
||||
addChild(layer);
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
layer->release();
|
||||
}
|
||||
|
|
|
@ -2,24 +2,22 @@
|
|||
#define _CURL_TEST_H_
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
|
||||
class CurlTest : public Layer
|
||||
DEFINE_TEST_SUITE(CurlTests);
|
||||
|
||||
class CurlTest : public TestCase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(CurlTest);
|
||||
|
||||
CurlTest();
|
||||
~CurlTest();
|
||||
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, cocos2d::Event *event);
|
||||
|
||||
private:
|
||||
cocos2d::Label* _label;
|
||||
};
|
||||
|
||||
class CurlTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
cocos2d::Label* _label;
|
||||
};
|
||||
|
||||
#endif // _CURL_TEST_H_
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
#include "CurrentLanguageTest.h"
|
||||
|
||||
CurrentLanguageTests::CurrentLanguageTests()
|
||||
{
|
||||
ADD_TEST_CASE(CurrentLanguageTest);
|
||||
}
|
||||
|
||||
CurrentLanguageTest::CurrentLanguageTest()
|
||||
{
|
||||
auto label = Label::createWithTTF("Current language Test", "fonts/arial.ttf", 28);
|
||||
|
@ -73,11 +78,3 @@ CurrentLanguageTest::CurrentLanguageTest()
|
|||
addChild(labelLanguageCode);
|
||||
}
|
||||
|
||||
void CurrentLanguageTestScene::runThisTest()
|
||||
{
|
||||
auto layer = new (std::nothrow) CurrentLanguageTest();
|
||||
addChild(layer);
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
layer->release();
|
||||
}
|
||||
|
|
|
@ -2,18 +2,16 @@
|
|||
#define _CURRENT_LANGUAGE_TEST_H_
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
|
||||
class CurrentLanguageTest : public Layer
|
||||
DEFINE_TEST_SUITE(CurrentLanguageTests);
|
||||
|
||||
class CurrentLanguageTest : public TestCase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(CurrentLanguageTest);
|
||||
|
||||
CurrentLanguageTest();
|
||||
};
|
||||
|
||||
class CurrentLanguageTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
#endif // _CURRENT_LANGUAGE_TEST_H_
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
#include "DataVisitorTest.h"
|
||||
#include "../testResource.h"
|
||||
|
||||
DataVisitorTests::DataVisitorTests()
|
||||
{
|
||||
ADD_TEST_CASE(PrettyPrinterDemo);
|
||||
}
|
||||
std::string PrettyPrinterDemo::title() const
|
||||
{
|
||||
return "PrettyPrinter Test";
|
||||
|
@ -36,7 +40,7 @@ void PrettyPrinterDemo::addSprite()
|
|||
|
||||
void PrettyPrinterDemo::onEnter()
|
||||
{
|
||||
Layer::onEnter();
|
||||
TestCase::onEnter();
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
|
||||
auto label = Label::createWithTTF(title().c_str(), "fonts/arial.ttf", 28);
|
||||
|
@ -75,12 +79,3 @@ void PrettyPrinterDemo::onEnter()
|
|||
// dict->acceptVisitor(vistor);
|
||||
// log("%s", vistor.getResult().c_str());
|
||||
}
|
||||
|
||||
void DataVisitorTestScene::runThisTest()
|
||||
{
|
||||
auto layer = new (std::nothrow) PrettyPrinterDemo();
|
||||
layer->autorelease();
|
||||
addChild(layer);
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
#ifndef __DATAVISITOR_TEST_H__
|
||||
#define __DATAVISITOR_TEST_H__
|
||||
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class PrettyPrinterDemo : public Layer
|
||||
DEFINE_TEST_SUITE(DataVisitorTests);
|
||||
|
||||
class PrettyPrinterDemo : public TestCase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(PrettyPrinterDemo);
|
||||
virtual std::string title() const;
|
||||
virtual std::string subtitle() const;
|
||||
virtual void onEnter() override;
|
||||
|
@ -16,12 +19,5 @@ protected:
|
|||
std::string _title;
|
||||
};
|
||||
|
||||
class DataVisitorTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
|
||||
CREATE_FUNC(DataVisitorTestScene);
|
||||
};
|
||||
|
||||
#endif // __DATAVISITOR_TEST_H__
|
||||
|
|
|
@ -11,110 +11,17 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
|
||||
Layer* nextSpriteTestAction();
|
||||
Layer* backSpriteTestAction();
|
||||
Layer* restartSpriteTestAction();
|
||||
|
||||
typedef Layer* (*NEWDRAWPRIMITIVESFUNC)();
|
||||
#define DRAWPRIMITIVES_CREATE_FUNC(className) \
|
||||
static Layer* create##className() \
|
||||
{ return new className(); }
|
||||
|
||||
DRAWPRIMITIVES_CREATE_FUNC(DrawPrimitivesTest);
|
||||
DRAWPRIMITIVES_CREATE_FUNC(DrawNodeTest);
|
||||
|
||||
static NEWDRAWPRIMITIVESFUNC createFunctions[] =
|
||||
DrawPrimitivesTests::DrawPrimitivesTests()
|
||||
{
|
||||
createDrawPrimitivesTest,
|
||||
createDrawNodeTest,
|
||||
};
|
||||
|
||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||
|
||||
static Layer* nextAction()
|
||||
{
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_LAYER;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
ADD_TEST_CASE(DrawPrimitivesTest);
|
||||
ADD_TEST_CASE(DrawNodeTest);
|
||||
}
|
||||
|
||||
static Layer* backAction()
|
||||
{
|
||||
sceneIdx--;
|
||||
int total = MAX_LAYER;
|
||||
if( sceneIdx < 0 )
|
||||
sceneIdx += total;
|
||||
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
static Layer* restartAction()
|
||||
{
|
||||
auto layer = (createFunctions[sceneIdx])();
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
// BaseLayer
|
||||
|
||||
BaseLayer::BaseLayer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void BaseLayer::onEnter()
|
||||
{
|
||||
BaseTest::onEnter();
|
||||
}
|
||||
|
||||
void BaseLayer::restartCallback(cocos2d::Ref *pSender)
|
||||
{
|
||||
auto s = new (std::nothrow) DrawPrimitivesTestScene();
|
||||
s->addChild(restartAction());
|
||||
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void BaseLayer::nextCallback(cocos2d::Ref *pSender)
|
||||
{
|
||||
auto s = new (std::nothrow) DrawPrimitivesTestScene();;
|
||||
s->addChild(nextAction());
|
||||
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void BaseLayer::backCallback(cocos2d::Ref *pSender)
|
||||
{
|
||||
auto s = new (std::nothrow) DrawPrimitivesTestScene();
|
||||
s->addChild(backAction());
|
||||
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
string BaseLayer::title() const
|
||||
string DrawPrimitivesBaseTest::title() const
|
||||
{
|
||||
return "No title";
|
||||
}
|
||||
|
||||
string BaseLayer::subtitle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
// DrawPrimitivesTest
|
||||
|
||||
DrawPrimitivesTest::DrawPrimitivesTest()
|
||||
|
@ -393,14 +300,6 @@ string DrawNodeTest::subtitle() const
|
|||
return "Testing DrawNode - batched draws. Concave polygons are BROKEN";
|
||||
}
|
||||
|
||||
void DrawPrimitivesTestScene::runThisTest()
|
||||
{
|
||||
auto layer = nextAction();
|
||||
addChild(layer);
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
||||
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
|
||||
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
||||
|
|
|
@ -2,27 +2,22 @@
|
|||
#define _DRAW_PRIMITIVES_TEST_H_
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class BaseLayer : public BaseTest
|
||||
DEFINE_TEST_SUITE(DrawPrimitivesTests);
|
||||
|
||||
class DrawPrimitivesBaseTest : public TestCase
|
||||
{
|
||||
public:
|
||||
BaseLayer();
|
||||
|
||||
void restartCallback(Ref* sender) override;
|
||||
void nextCallback(Ref* sender) override;
|
||||
void backCallback(Ref* sender) override;
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void onEnter() override;
|
||||
};
|
||||
|
||||
class DrawPrimitivesTest : public BaseLayer
|
||||
class DrawPrimitivesTest : public DrawPrimitivesBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(DrawPrimitivesTest);
|
||||
DrawPrimitivesTest();
|
||||
|
||||
virtual std::string title() const override;
|
||||
|
@ -34,19 +29,15 @@ protected:
|
|||
CustomCommand _customCommand;
|
||||
};
|
||||
|
||||
class DrawNodeTest : public BaseLayer
|
||||
class DrawNodeTest : public DrawPrimitivesBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(DrawNodeTest);
|
||||
|
||||
DrawNodeTest();
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class DrawPrimitivesTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -11,6 +11,16 @@ enum
|
|||
kTagLabel = 2,
|
||||
};
|
||||
|
||||
EffectAdvanceTests::EffectAdvanceTests()
|
||||
{
|
||||
ADD_TEST_CASE(Effect3);
|
||||
ADD_TEST_CASE(Effect2);
|
||||
ADD_TEST_CASE(Effect1);
|
||||
ADD_TEST_CASE(Effect4);
|
||||
ADD_TEST_CASE(Effect5);
|
||||
ADD_TEST_CASE(Issue631);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Effect1
|
||||
|
@ -18,7 +28,7 @@ enum
|
|||
//------------------------------------------------------------------
|
||||
void Effect1::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
EffectAdvanceBaseTest::onEnter();
|
||||
|
||||
//auto target = getChildByTag(kTagBackground);
|
||||
|
||||
|
@ -53,7 +63,7 @@ std::string Effect1::title() const
|
|||
//------------------------------------------------------------------
|
||||
void Effect2::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
EffectAdvanceBaseTest::onEnter();
|
||||
|
||||
//auto target = getChildByTag(kTagBackground);
|
||||
|
||||
|
@ -95,7 +105,7 @@ std::string Effect2::title() const
|
|||
//------------------------------------------------------------------
|
||||
void Effect3::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
EffectAdvanceBaseTest::onEnter();
|
||||
//auto bg = getChildByTag(kTagBackground);
|
||||
//auto target1 = bg->getChildByTag(kTagSprite1);
|
||||
//auto target2 = bg->getChildByTag(kTagSprite2);
|
||||
|
@ -153,7 +163,7 @@ private:
|
|||
|
||||
void Effect4::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
EffectAdvanceBaseTest::onEnter();
|
||||
//Node* gridNode = NodeGrid::create();
|
||||
|
||||
auto lens = Lens3D::create(10, Size(32,24), Vec2(100,180), 150);
|
||||
|
@ -189,7 +199,7 @@ std::string Effect4::title() const
|
|||
//------------------------------------------------------------------
|
||||
void Effect5::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
EffectAdvanceBaseTest::onEnter();
|
||||
|
||||
//CCDirector::getInstance()->setProjection(DirectorProjection2D);
|
||||
|
||||
|
@ -214,7 +224,7 @@ std::string Effect5::title() const
|
|||
|
||||
void Effect5::onExit()
|
||||
{
|
||||
EffectAdvanceTextLayer::onExit();
|
||||
EffectAdvanceBaseTest::onExit();
|
||||
|
||||
Director::getInstance()->setProjection(Director::Projection::_3D);
|
||||
}
|
||||
|
@ -226,7 +236,7 @@ void Effect5::onExit()
|
|||
//------------------------------------------------------------------
|
||||
void Issue631::onEnter()
|
||||
{
|
||||
EffectAdvanceTextLayer::onEnter();
|
||||
EffectAdvanceBaseTest::onEnter();
|
||||
|
||||
auto effect = Sequence::create( DelayTime::create(2.0f), Shaky3D::create(5.0f, Size(5, 5), 16, false), nullptr);
|
||||
|
||||
|
@ -267,76 +277,13 @@ std::string Issue631::subtitle() const
|
|||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// EffectAdvanceTextLayer
|
||||
// EffectAdvanceBaseTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
enum
|
||||
void EffectAdvanceBaseTest::onEnter(void)
|
||||
{
|
||||
IDC_NEXT = 100,
|
||||
IDC_BACK,
|
||||
IDC_RESTART
|
||||
};
|
||||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
#define MAX_LAYER 6
|
||||
|
||||
Layer* nextEffectAdvanceAction();
|
||||
Layer* backEffectAdvanceAction();
|
||||
Layer* restartEffectAdvanceAction();
|
||||
|
||||
Layer* createEffectAdvanceLayer(int nIndex)
|
||||
{
|
||||
switch(nIndex)
|
||||
{
|
||||
case 0: return new Effect3();
|
||||
case 1: return new Effect2();
|
||||
case 2: return new Effect1();
|
||||
case 3: return new Effect4();
|
||||
case 4: return new Effect5();
|
||||
case 5: return new Issue631();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Layer* nextEffectAdvanceAction()
|
||||
{
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % MAX_LAYER;
|
||||
|
||||
auto layer = createEffectAdvanceLayer(sceneIdx);
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
Layer* backEffectAdvanceAction()
|
||||
{
|
||||
sceneIdx--;
|
||||
int total = MAX_LAYER;
|
||||
if( sceneIdx < 0 )
|
||||
sceneIdx += total;
|
||||
|
||||
auto layer = createEffectAdvanceLayer(sceneIdx);
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
Layer* restartEffectAdvanceAction()
|
||||
{
|
||||
auto layer = createEffectAdvanceLayer(sceneIdx);
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
|
||||
void EffectAdvanceTextLayer::onEnter(void)
|
||||
{
|
||||
BaseTest::onEnter();
|
||||
TestCase::onEnter();
|
||||
|
||||
_bgNode = NodeGrid::create();
|
||||
_bgNode->setAnchorPoint(Vec2(0.5,0.5));
|
||||
|
@ -371,50 +318,16 @@ void EffectAdvanceTextLayer::onEnter(void)
|
|||
|
||||
}
|
||||
|
||||
EffectAdvanceTextLayer::~EffectAdvanceTextLayer(void)
|
||||
EffectAdvanceBaseTest::~EffectAdvanceBaseTest(void)
|
||||
{
|
||||
}
|
||||
|
||||
std::string EffectAdvanceTextLayer::title() const
|
||||
std::string EffectAdvanceBaseTest::title() const
|
||||
{
|
||||
return "No title";
|
||||
}
|
||||
|
||||
std::string EffectAdvanceTextLayer::subtitle() const
|
||||
std::string EffectAdvanceBaseTest::subtitle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
void EffectAdvanceTextLayer::restartCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) EffectAdvanceScene();
|
||||
s->addChild(restartEffectAdvanceAction());
|
||||
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void EffectAdvanceTextLayer::nextCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) EffectAdvanceScene();
|
||||
s->addChild( nextEffectAdvanceAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
|
||||
s->release();
|
||||
}
|
||||
|
||||
void EffectAdvanceTextLayer::backCallback(Ref* sender)
|
||||
{
|
||||
auto s = new (std::nothrow) EffectAdvanceScene();
|
||||
s->addChild( backEffectAdvanceAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void EffectAdvanceScene::runThisTest()
|
||||
{
|
||||
auto layer = nextEffectAdvanceAction();
|
||||
|
||||
addChild(layer);
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
#define _EFFECT_ADVANCED_TEST_H_
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
|
||||
class EffectAdvanceTextLayer: public BaseTest
|
||||
DEFINE_TEST_SUITE(EffectAdvanceTests);
|
||||
|
||||
class EffectAdvanceBaseTest: public TestCase
|
||||
{
|
||||
protected:
|
||||
TextureAtlas* _atlas;
|
||||
|
@ -18,64 +19,60 @@ protected:
|
|||
|
||||
public:
|
||||
virtual void onEnter() override;
|
||||
~EffectAdvanceTextLayer(void);
|
||||
~EffectAdvanceBaseTest(void);
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void restartCallback(Ref* sender) override;
|
||||
void nextCallback(Ref* sender) override;
|
||||
void backCallback(Ref* sender) override;
|
||||
};
|
||||
|
||||
class Effect1 : public EffectAdvanceTextLayer
|
||||
class Effect1 : public EffectAdvanceBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Effect1);
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
class Effect2 : public EffectAdvanceTextLayer
|
||||
class Effect2 : public EffectAdvanceBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Effect2);
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
class Effect3 : public EffectAdvanceTextLayer
|
||||
class Effect3 : public EffectAdvanceBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Effect3);
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
class Effect4 : public EffectAdvanceTextLayer
|
||||
class Effect4 : public EffectAdvanceBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Effect4);
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
class Effect5 : public EffectAdvanceTextLayer
|
||||
class Effect5 : public EffectAdvanceBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Effect5);
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
class Issue631 : public EffectAdvanceTextLayer
|
||||
class Issue631 : public EffectAdvanceBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Issue631);
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class EffectAdvanceScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8,7 +8,6 @@ enum {
|
|||
kTagLabel = 2,
|
||||
};
|
||||
|
||||
static int actionIdx=0;
|
||||
static std::string effectsList[] =
|
||||
{
|
||||
"Shaky3D",
|
||||
|
@ -35,6 +34,15 @@ static std::string effectsList[] =
|
|||
"PageTurn3D",
|
||||
};
|
||||
|
||||
EffectTests::EffectTests()
|
||||
{
|
||||
int index = 0;
|
||||
for (auto& effectName : effectsList)
|
||||
{
|
||||
addTestCase(effectName, [index](){return EffectBaseTest::create(index); });
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
class Shaky3DDemo : public Shaky3D
|
||||
{
|
||||
|
@ -281,10 +289,9 @@ public:
|
|||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// TextLayer
|
||||
// EffectBaseTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
#define MAX_LAYER 22
|
||||
|
||||
ActionInterval* createEffect(int nIndex, float t)
|
||||
{
|
||||
|
@ -320,35 +327,20 @@ ActionInterval* createEffect(int nIndex, float t)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
ActionInterval* getAction()
|
||||
{
|
||||
auto pEffect = createEffect(actionIdx, 3);
|
||||
|
||||
return pEffect;
|
||||
}
|
||||
|
||||
void EffectTestScene::runThisTest()
|
||||
{
|
||||
addChild(TextLayer::create());
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
||||
#define SID_RESTART 1
|
||||
|
||||
TextLayer::TextLayer(void)
|
||||
: BaseTest()
|
||||
EffectBaseTest::EffectBaseTest(int actionIdx)
|
||||
{
|
||||
LayerColor *background = LayerColor::create( Color4B(32,128,32,255) );
|
||||
this->addChild(background,-20);
|
||||
|
||||
_gridNodeTarget = NodeGrid::create();
|
||||
auto effect = getAction();
|
||||
auto effect = createEffect(actionIdx, 3);
|
||||
_gridNodeTarget->runAction(effect);
|
||||
addChild(_gridNodeTarget, 0, kTagBackground);
|
||||
|
||||
auto bg = Sprite::create(s_back3);
|
||||
_gridNodeTarget->addChild(bg, 0);
|
||||
// bg->setAnchorPoint( Vec2::ZERO );
|
||||
bg->setPosition(VisibleRect::center());
|
||||
|
||||
auto grossini = Sprite::create(s_pathSister2);
|
||||
|
@ -371,69 +363,16 @@ TextLayer::TextLayer(void)
|
|||
addChild(label);
|
||||
label->setTag( kTagLabel );
|
||||
|
||||
schedule( CC_SCHEDULE_SELECTOR(TextLayer::checkAnim) );
|
||||
schedule( CC_SCHEDULE_SELECTOR(EffectBaseTest::checkAnim) );
|
||||
}
|
||||
|
||||
void TextLayer::checkAnim(float dt)
|
||||
void EffectBaseTest::checkAnim(float dt)
|
||||
{
|
||||
//auto s2 = getChildByTag(kTagBackground);
|
||||
if ( _gridNodeTarget->getNumberOfRunningActions() == 0 && _gridNodeTarget->getGrid() != nullptr)
|
||||
_gridNodeTarget->setGrid(nullptr);;
|
||||
}
|
||||
|
||||
|
||||
TextLayer::~TextLayer(void)
|
||||
EffectBaseTest::~EffectBaseTest(void)
|
||||
{
|
||||
}
|
||||
|
||||
// TextLayer* TextLayer::node()
|
||||
// {
|
||||
// return TextLayer::create();
|
||||
// }
|
||||
|
||||
TextLayer* TextLayer::create()
|
||||
{
|
||||
auto layer = new (std::nothrow) TextLayer();
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
void TextLayer::onEnter()
|
||||
{
|
||||
BaseTest::onEnter();
|
||||
}
|
||||
|
||||
void TextLayer::newScene()
|
||||
{
|
||||
auto s = new (std::nothrow) EffectTestScene();
|
||||
auto child = TextLayer::create();
|
||||
s->addChild(child);
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void TextLayer::restartCallback(Ref* sender)
|
||||
{
|
||||
newScene();
|
||||
}
|
||||
|
||||
void TextLayer::nextCallback(Ref* sender)
|
||||
{
|
||||
// update the action index
|
||||
actionIdx++;
|
||||
actionIdx = actionIdx % MAX_LAYER;
|
||||
|
||||
newScene();
|
||||
}
|
||||
|
||||
void TextLayer::backCallback(Ref* sender)
|
||||
{
|
||||
// update the action index
|
||||
actionIdx--;
|
||||
int total = MAX_LAYER;
|
||||
if( actionIdx < 0 )
|
||||
actionIdx += total;
|
||||
|
||||
newScene();
|
||||
}
|
||||
|
|
|
@ -1,35 +1,36 @@
|
|||
#ifndef _EFFECTS_TEST_H_
|
||||
#define _EFFECTS_TEST_H_
|
||||
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
|
||||
class EffectTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
DEFINE_TEST_SUITE(EffectTests);
|
||||
|
||||
class TextLayer : public BaseTest
|
||||
class EffectBaseTest : public TestCase
|
||||
{
|
||||
protected:
|
||||
//UxString _title;
|
||||
NodeGrid* _gridNodeTarget;
|
||||
public:
|
||||
TextLayer(void);
|
||||
~TextLayer(void);
|
||||
static EffectBaseTest* create(int index)
|
||||
{
|
||||
auto ret = new (std::nothrow) EffectBaseTest(index);
|
||||
if (ret && ret->init())
|
||||
{
|
||||
ret->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
delete ret;
|
||||
ret = nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
EffectBaseTest(int index);
|
||||
~EffectBaseTest();
|
||||
|
||||
void checkAnim(float dt);
|
||||
|
||||
virtual void onEnter() override;
|
||||
|
||||
void restartCallback(Ref* sender) override;
|
||||
void nextCallback(Ref* sender) override;
|
||||
void backCallback(Ref* sender) override;
|
||||
|
||||
void newScene();
|
||||
|
||||
static TextLayer* create();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,201 +6,177 @@ const char* sceneManifests[] = {"AMTestScene1/project.manifest", "AMTestScene2/p
|
|||
const char* storagePaths[] = {"CppTests/AssetsManagerExTest/scene1/", "CppTests/AssetsManagerExTest/scene2/", "CppTests/AssetsManagerExTest/scene3"};
|
||||
const char* backgroundPaths[] = {"Images/assetMgrBackground1.jpg", "Images/assetMgrBackground2.png", "Images/assetMgrBackground3.png"};
|
||||
|
||||
AssetsManagerExTestLayer::AssetsManagerExTestLayer(const std::string& spritePath)
|
||||
: _spritePath(spritePath)
|
||||
AssetsManagerExTests::AssetsManagerExTests()
|
||||
{
|
||||
addTestCase("AssetsManager Test1", [](){ return AssetsManagerExLoaderScene::create(0); });
|
||||
addTestCase("AssetsManager Test2", [](){ return AssetsManagerExLoaderScene::create(1); });
|
||||
addTestCase("AssetsManager Test3", [](){ return AssetsManagerExLoaderScene::create(2); });
|
||||
}
|
||||
|
||||
AssetsManagerExTestLayer::~AssetsManagerExTestLayer(void)
|
||||
AssetsManagerExLoaderScene* AssetsManagerExLoaderScene::create(int testIndex)
|
||||
{
|
||||
}
|
||||
|
||||
std::string AssetsManagerExTestLayer::title() const
|
||||
{
|
||||
return "AssetsManagerExTest";
|
||||
}
|
||||
|
||||
void AssetsManagerExTestLayer::onEnter()
|
||||
{
|
||||
BaseTest::onEnter();
|
||||
_background = Sprite::create(_spritePath);
|
||||
if (_background)
|
||||
auto scene = new (std::nothrow) AssetsManagerExLoaderScene(testIndex);
|
||||
if (scene && scene->init())
|
||||
{
|
||||
addChild(_background, 1);
|
||||
_background->setPosition( VisibleRect::center() );
|
||||
}
|
||||
}
|
||||
|
||||
void AssetsManagerExTestLayer::restartCallback(Ref* sender)
|
||||
{
|
||||
}
|
||||
|
||||
void AssetsManagerExTestLayer::nextCallback(Ref* sender)
|
||||
{
|
||||
if (AssetsManagerExLoaderScene::currentScene < 2)
|
||||
{
|
||||
AssetsManagerExLoaderScene::currentScene++;
|
||||
scene->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
AssetsManagerExLoaderScene::currentScene = 0;
|
||||
delete scene;
|
||||
scene = nullptr;
|
||||
}
|
||||
auto scene = new AssetsManagerExLoaderScene();
|
||||
scene->runThisTest();
|
||||
scene->release();
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void AssetsManagerExTestLayer::backCallback(Ref* sender)
|
||||
{
|
||||
if (AssetsManagerExLoaderScene::currentScene > 0)
|
||||
{
|
||||
AssetsManagerExLoaderScene::currentScene--;
|
||||
}
|
||||
else AssetsManagerExLoaderScene::currentScene = 2;
|
||||
auto scene = new AssetsManagerExLoaderScene();
|
||||
scene->runThisTest();
|
||||
scene->release();
|
||||
}
|
||||
|
||||
|
||||
AssetsManagerExTestScene::AssetsManagerExTestScene(std::string background)
|
||||
{
|
||||
auto layer = new AssetsManagerExTestLayer(background);
|
||||
addChild(layer);
|
||||
layer->release();
|
||||
}
|
||||
|
||||
void AssetsManagerExTestScene::runThisTest()
|
||||
{
|
||||
}
|
||||
|
||||
int AssetsManagerExLoaderScene::currentScene = 0;
|
||||
AssetsManagerExLoaderScene::AssetsManagerExLoaderScene()
|
||||
: _progress(nullptr)
|
||||
AssetsManagerExLoaderScene::AssetsManagerExLoaderScene(int testIndex)
|
||||
: _testIndex(testIndex)
|
||||
, _loadLayer(nullptr)
|
||||
, _downloadMenu(nullptr)
|
||||
, _am(nullptr)
|
||||
, _progress(nullptr)
|
||||
, _amListener(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AssetsManagerExLoaderScene::runThisTest()
|
||||
bool AssetsManagerExLoaderScene::init()
|
||||
{
|
||||
int currentId = currentScene;
|
||||
std::string manifestPath = sceneManifests[currentId], storagePath = FileUtils::getInstance()->getWritablePath() + storagePaths[currentId];
|
||||
CCLOG("Storage path for this test : %s", storagePath.c_str());
|
||||
|
||||
Sprite *sprite = Sprite::create("Images/Icon.png");
|
||||
auto layer = Layer::create();
|
||||
addChild(layer);
|
||||
layer->addChild(sprite);
|
||||
if (!TestCase::init())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto downloadLabel = Label::createWithTTF("Start Download", "fonts/arial.ttf", 16);
|
||||
auto downloadItem = MenuItemLabel::create(downloadLabel, CC_CALLBACK_1(AssetsManagerExLoaderScene::startDownloadCallback, this));
|
||||
downloadItem->setPosition(Vec2(VisibleRect::center().x, VisibleRect::bottom().y + 100));
|
||||
_downloadMenu = Menu::create(downloadItem, nullptr);
|
||||
_downloadMenu->setPosition(Vec2::ZERO);
|
||||
this->addChild(_downloadMenu, 1);
|
||||
|
||||
_loadLayer = Layer::create();
|
||||
addChild(_loadLayer);
|
||||
|
||||
auto sprite = Sprite::create("Images/Icon.png");
|
||||
_loadLayer->addChild(sprite);
|
||||
sprite->setPosition( VisibleRect::center() );
|
||||
|
||||
TTFConfig config("fonts/tahoma.ttf", 30);
|
||||
_progress = Label::createWithTTF(config, "0%", TextHAlignment::CENTER);
|
||||
_progress->setPosition( Vec2(VisibleRect::center().x, VisibleRect::center().y + 50) );
|
||||
layer->addChild(_progress);
|
||||
_loadLayer->addChild(_progress);
|
||||
|
||||
std::string manifestPath = sceneManifests[_testIndex], storagePath = FileUtils::getInstance()->getWritablePath() + storagePaths[_testIndex];
|
||||
CCLOG("Storage path for this test : %s", storagePath.c_str());
|
||||
_am = AssetsManagerEx::create(manifestPath, storagePath);
|
||||
_am->retain();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AssetsManagerExLoaderScene::onLoadEnd()
|
||||
{
|
||||
removeChild(_loadLayer, true);
|
||||
_loadLayer = nullptr;
|
||||
|
||||
auto backgroundSprite = Sprite::create(backgroundPaths[_testIndex]);
|
||||
addChild(backgroundSprite, 1);
|
||||
backgroundSprite->setPosition(VisibleRect::center());
|
||||
}
|
||||
|
||||
void AssetsManagerExLoaderScene::startDownloadCallback(Ref* sender)
|
||||
{
|
||||
removeChild(_downloadMenu);
|
||||
_downloadMenu = nullptr;
|
||||
|
||||
if (!_am->getLocalManifest()->isLoaded())
|
||||
{
|
||||
CCLOG("Fail to update assets, step skipped.");
|
||||
AssetsManagerExTestScene *scene = new AssetsManagerExTestScene(backgroundPaths[currentId]);
|
||||
Director::getInstance()->replaceScene(scene);
|
||||
scene->release();
|
||||
onLoadEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
_amListener = cocos2d::extension::EventListenerAssetsManagerEx::create(_am, [currentId, this](EventAssetsManagerEx* event){
|
||||
int testIndex = _testIndex;
|
||||
_amListener = cocos2d::extension::EventListenerAssetsManagerEx::create(_am, [testIndex, this](EventAssetsManagerEx* event){
|
||||
static int failCount = 0;
|
||||
AssetsManagerExTestScene *scene;
|
||||
switch (event->getEventCode())
|
||||
{
|
||||
case EventAssetsManagerEx::EventCode::ERROR_NO_LOCAL_MANIFEST:
|
||||
case EventAssetsManagerEx::EventCode::ERROR_NO_LOCAL_MANIFEST:
|
||||
{
|
||||
CCLOG("No local manifest file found, skip assets update.");
|
||||
this->onLoadEnd();
|
||||
}
|
||||
break;
|
||||
case EventAssetsManagerEx::EventCode::UPDATE_PROGRESSION:
|
||||
{
|
||||
std::string assetId = event->getAssetId();
|
||||
float percent = event->getPercent();
|
||||
std::string str;
|
||||
if (assetId == AssetsManagerEx::VERSION_ID)
|
||||
{
|
||||
CCLOG("No local manifest file found, skip assets update.");
|
||||
scene = new AssetsManagerExTestScene(backgroundPaths[currentId]);
|
||||
Director::getInstance()->replaceScene(scene);
|
||||
scene->release();
|
||||
str = StringUtils::format("Version file: %.2f", percent) + "%";
|
||||
}
|
||||
break;
|
||||
case EventAssetsManagerEx::EventCode::UPDATE_PROGRESSION:
|
||||
else if (assetId == AssetsManagerEx::MANIFEST_ID)
|
||||
{
|
||||
std::string assetId = event->getAssetId();
|
||||
float percent = event->getPercent();
|
||||
std::string str;
|
||||
if (assetId == AssetsManagerEx::VERSION_ID)
|
||||
{
|
||||
str = StringUtils::format("Version file: %.2f", percent) + "%";
|
||||
}
|
||||
else if (assetId == AssetsManagerEx::MANIFEST_ID)
|
||||
{
|
||||
str = StringUtils::format("Manifest file: %.2f", percent) + "%";
|
||||
}
|
||||
else
|
||||
{
|
||||
str = StringUtils::format("%.2f", percent) + "%";
|
||||
CCLOG("%.2f Percent", percent);
|
||||
}
|
||||
if (this->_progress != nullptr)
|
||||
this->_progress->setString(str);
|
||||
str = StringUtils::format("Manifest file: %.2f", percent) + "%";
|
||||
}
|
||||
break;
|
||||
case EventAssetsManagerEx::EventCode::ERROR_DOWNLOAD_MANIFEST:
|
||||
case EventAssetsManagerEx::EventCode::ERROR_PARSE_MANIFEST:
|
||||
else
|
||||
{
|
||||
CCLOG("Fail to download manifest file, update skipped.");
|
||||
scene = new AssetsManagerExTestScene(backgroundPaths[currentId]);
|
||||
Director::getInstance()->replaceScene(scene);
|
||||
scene->release();
|
||||
str = StringUtils::format("%.2f", percent) + "%";
|
||||
CCLOG("%.2f Percent", percent);
|
||||
}
|
||||
break;
|
||||
case EventAssetsManagerEx::EventCode::ALREADY_UP_TO_DATE:
|
||||
case EventAssetsManagerEx::EventCode::UPDATE_FINISHED:
|
||||
{
|
||||
CCLOG("Update finished. %s", event->getMessage().c_str());
|
||||
scene = new AssetsManagerExTestScene(backgroundPaths[currentId]);
|
||||
Director::getInstance()->replaceScene(scene);
|
||||
scene->release();
|
||||
}
|
||||
break;
|
||||
case EventAssetsManagerEx::EventCode::UPDATE_FAILED:
|
||||
{
|
||||
CCLOG("Update failed. %s", event->getMessage().c_str());
|
||||
if (this->_progress != nullptr)
|
||||
this->_progress->setString(str);
|
||||
}
|
||||
break;
|
||||
case EventAssetsManagerEx::EventCode::ERROR_DOWNLOAD_MANIFEST:
|
||||
case EventAssetsManagerEx::EventCode::ERROR_PARSE_MANIFEST:
|
||||
{
|
||||
CCLOG("Fail to download manifest file, update skipped.");
|
||||
this->onLoadEnd();
|
||||
}
|
||||
break;
|
||||
case EventAssetsManagerEx::EventCode::ALREADY_UP_TO_DATE:
|
||||
case EventAssetsManagerEx::EventCode::UPDATE_FINISHED:
|
||||
{
|
||||
CCLOG("Update finished. %s", event->getMessage().c_str());
|
||||
this->onLoadEnd();
|
||||
}
|
||||
break;
|
||||
case EventAssetsManagerEx::EventCode::UPDATE_FAILED:
|
||||
{
|
||||
CCLOG("Update failed. %s", event->getMessage().c_str());
|
||||
|
||||
failCount ++;
|
||||
if (failCount < 5)
|
||||
{
|
||||
_am->downloadFailedAssets();
|
||||
}
|
||||
else
|
||||
{
|
||||
CCLOG("Reach maximum fail count, exit update process");
|
||||
failCount = 0;
|
||||
scene = new AssetsManagerExTestScene(backgroundPaths[currentId]);
|
||||
Director::getInstance()->replaceScene(scene);
|
||||
scene->release();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EventAssetsManagerEx::EventCode::ERROR_UPDATING:
|
||||
failCount++;
|
||||
if (failCount < 5)
|
||||
{
|
||||
CCLOG("Asset %s : %s", event->getAssetId().c_str(), event->getMessage().c_str());
|
||||
_am->downloadFailedAssets();
|
||||
}
|
||||
break;
|
||||
case EventAssetsManagerEx::EventCode::ERROR_DECOMPRESS:
|
||||
else
|
||||
{
|
||||
CCLOG("%s", event->getMessage().c_str());
|
||||
CCLOG("Reach maximum fail count, exit update process");
|
||||
failCount = 0;
|
||||
this->onLoadEnd();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case EventAssetsManagerEx::EventCode::ERROR_UPDATING:
|
||||
{
|
||||
CCLOG("Asset %s : %s", event->getAssetId().c_str(), event->getMessage().c_str());
|
||||
}
|
||||
break;
|
||||
case EventAssetsManagerEx::EventCode::ERROR_DECOMPRESS:
|
||||
{
|
||||
CCLOG("%s", event->getMessage().c_str());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_amListener, 1);
|
||||
|
||||
|
||||
_am->update();
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,5 +184,10 @@ void AssetsManagerExLoaderScene::onExit()
|
|||
{
|
||||
_eventDispatcher->removeEventListener(_amListener);
|
||||
_am->release();
|
||||
Scene::onExit();
|
||||
TestCase::onExit();
|
||||
}
|
||||
|
||||
std::string AssetsManagerExLoaderScene::title() const
|
||||
{
|
||||
return "AssetsManagerExTest";
|
||||
}
|
||||
|
|
|
@ -2,52 +2,37 @@
|
|||
#define __AssetsManagerEx_Test_H__
|
||||
|
||||
#include "extensions/cocos-ext.h"
|
||||
#include "../../testBasic.h"
|
||||
#include "../../BaseTest.h"
|
||||
|
||||
USING_NS_CC;
|
||||
USING_NS_CC_EXT;
|
||||
|
||||
class AssetsManagerExTestLayer : public BaseTest
|
||||
{
|
||||
public:
|
||||
AssetsManagerExTestLayer(const std::string& spritePath);
|
||||
~AssetsManagerExTestLayer(void);
|
||||
|
||||
virtual std::string title() const override;
|
||||
void onEnter() override;
|
||||
|
||||
virtual void restartCallback(Ref* sender) override;
|
||||
virtual void nextCallback(Ref* sender) override;
|
||||
virtual void backCallback(Ref* sender) override;
|
||||
|
||||
private:
|
||||
Sprite *_background;
|
||||
std::string _spritePath;
|
||||
};
|
||||
DEFINE_TEST_SUITE(AssetsManagerExTests);
|
||||
|
||||
class AssetsManagerExTestScene : public TestScene
|
||||
class AssetsManagerExLoaderScene : public TestCase
|
||||
{
|
||||
public:
|
||||
AssetsManagerExTestScene(std::string background);
|
||||
virtual void runThisTest() override;
|
||||
};
|
||||
static AssetsManagerExLoaderScene* create(int testIndex);
|
||||
|
||||
class AssetsManagerExLoaderScene : public TestScene
|
||||
{
|
||||
public:
|
||||
AssetsManagerExLoaderScene();
|
||||
|
||||
virtual void runThisTest() override;
|
||||
AssetsManagerExLoaderScene(int testIndex);
|
||||
|
||||
void startDownloadCallback(Ref* sender);
|
||||
|
||||
virtual std::string title() const;
|
||||
|
||||
virtual bool init() override;
|
||||
virtual void onExit() override;
|
||||
|
||||
static int currentScene;
|
||||
|
||||
private:
|
||||
int _testIndex;
|
||||
Layer* _loadLayer;
|
||||
Menu* _downloadMenu;
|
||||
|
||||
AssetsManagerEx *_am;
|
||||
Label *_progress;
|
||||
EventListenerAssetsManagerEx* _amListener;
|
||||
|
||||
void onLoadEnd();
|
||||
};
|
||||
|
||||
#endif /* defined(__AssetsManagerEx_Test_H__) */
|
||||
|
|
|
@ -8,207 +8,61 @@
|
|||
using namespace cocos2d;
|
||||
using namespace cocostudio;
|
||||
|
||||
Layer *NextAnimationTest();
|
||||
Layer *BackAnimationTest();
|
||||
Layer *RestartAnimationTest();
|
||||
|
||||
static int s_nActionIdx = -1;
|
||||
|
||||
|
||||
Layer *CreateAnimationLayer(int index)
|
||||
CocoStudioActionTimelineTests::CocoStudioActionTimelineTests()
|
||||
{
|
||||
Layer *pLayer = nullptr;
|
||||
switch(index)
|
||||
ADD_TEST_CASE(TestActionTimeline);
|
||||
ADD_TEST_CASE(TestChangePlaySection);
|
||||
ADD_TEST_CASE(TestTimelineFrameEvent);
|
||||
ADD_TEST_CASE(TestTimelinePerformance);
|
||||
ADD_TEST_CASE(TestTimelineAnimationList);
|
||||
ADD_TEST_CASE(TestTimelineProjectNode);
|
||||
ADD_TEST_CASE(TestProjectNodeForSimulator);
|
||||
ADD_TEST_CASE(TestTimelineNodeLoadedCallback);
|
||||
}
|
||||
|
||||
CocoStudioActionTimelineTests::~CocoStudioActionTimelineTests()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool ActionTimelineBaseTest::init()
|
||||
{
|
||||
if (TestCase::init())
|
||||
{
|
||||
case TEST_ANIMATIONELEMENT:
|
||||
pLayer = new (std::nothrow) TestActionTimeline();
|
||||
break;
|
||||
case TEST_CHANGE_PLAY_SECTION:
|
||||
pLayer = new (std::nothrow) TestChangePlaySection();
|
||||
break;
|
||||
/*
|
||||
case TEST_TIMELINE_FRAME_EVENT:
|
||||
pLayer = new (std::nothrow) TestTimelineFrameEvent();
|
||||
break;
|
||||
*/
|
||||
case TEST_TIMELINE_PERFORMACE:
|
||||
pLayer = new (std::nothrow) TestTimelinePerformance();
|
||||
break;
|
||||
case TEST_TIMELINEACTION_ANIMATIONLIST:
|
||||
pLayer = new (std::nothrow) TestTimelineAnimationList();
|
||||
break;
|
||||
case TEST_TIMELINEPROJECTNODE:
|
||||
pLayer = new (std::nothrow) TestTimelineProjectNode();
|
||||
break;
|
||||
case TEST_PROJECTNODEFORSIMALATOR:
|
||||
pLayer = new (std::nothrow) TestProjectNodeForSimulator;
|
||||
break;
|
||||
case TEST_NODELOADEDCALLBACK:
|
||||
pLayer = new (std::nothrow)TestTimelineNodeLoadedCallback;
|
||||
break;
|
||||
default:
|
||||
CCLOG("NONE OF THIS TEST LAYER");
|
||||
break;
|
||||
Sprite *bg = Sprite::create("armature/bg.jpg");
|
||||
bg->setPosition(VisibleRect::center());
|
||||
|
||||
float scaleX = VisibleRect::getVisibleRect().size.width / bg->getContentSize().width;
|
||||
float scaleY = VisibleRect::getVisibleRect().size.height / bg->getContentSize().height;
|
||||
|
||||
bg->setScaleX(scaleX);
|
||||
bg->setScaleY(scaleY);
|
||||
|
||||
addChild(bg);
|
||||
|
||||
setGLProgram(ShaderCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return pLayer;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Layer *NextAnimationTest()
|
||||
void ActionTimelineBaseTest::onExit()
|
||||
{
|
||||
++s_nActionIdx;
|
||||
s_nActionIdx = s_nActionIdx % TEST_ANIMATION_LAYER_COUNT;
|
||||
|
||||
Layer *pLayer = CreateAnimationLayer(s_nActionIdx);
|
||||
pLayer->autorelease();
|
||||
|
||||
return pLayer;
|
||||
}
|
||||
|
||||
Layer *BackAnimationTest()
|
||||
{
|
||||
--s_nActionIdx;
|
||||
if( s_nActionIdx < 0 )
|
||||
s_nActionIdx += TEST_ANIMATION_LAYER_COUNT;
|
||||
|
||||
Layer *pLayer = CreateAnimationLayer(s_nActionIdx);
|
||||
pLayer->autorelease();
|
||||
|
||||
return pLayer;
|
||||
}
|
||||
|
||||
Layer *RestartAnimationTest()
|
||||
{
|
||||
Layer *pLayer = CreateAnimationLayer(s_nActionIdx);
|
||||
pLayer->autorelease();
|
||||
|
||||
return pLayer;
|
||||
}
|
||||
|
||||
|
||||
ActionTimelineTestScene::ActionTimelineTestScene(bool bPortrait)
|
||||
{
|
||||
TestScene::init();
|
||||
|
||||
Sprite *bg = Sprite::create("armature/bg.jpg");
|
||||
bg->setPosition(VisibleRect::center());
|
||||
|
||||
float scaleX = VisibleRect::getVisibleRect().size.width / bg->getContentSize().width;
|
||||
float scaleY = VisibleRect::getVisibleRect().size.height / bg->getContentSize().height;
|
||||
|
||||
bg->setScaleX(scaleX);
|
||||
bg->setScaleY(scaleY);
|
||||
|
||||
addChild(bg);
|
||||
}
|
||||
|
||||
void ActionTimelineTestScene::runThisTest()
|
||||
{
|
||||
s_nActionIdx = -1;
|
||||
addChild(NextAnimationTest());
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
||||
void ActionTimelineTestScene::MainMenuCallback(Ref *pSender)
|
||||
{
|
||||
//TestScene::MainMenuCallback(pSender);
|
||||
|
||||
removeAllChildren();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ActionTimelineTestLayer::onEnter()
|
||||
{
|
||||
|
||||
Layer::onEnter();
|
||||
|
||||
// add title and subtitle
|
||||
std::string str = title();
|
||||
const char *title = str.c_str();
|
||||
auto label = Label::createWithSystemFont(title, "Arial", 18);
|
||||
label->setColor(Color3B(0, 0, 0));
|
||||
addChild(label, 1, 10000);
|
||||
label->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y - 30) );
|
||||
|
||||
std::string strSubtitle = subtitle();
|
||||
if( ! strSubtitle.empty() )
|
||||
{
|
||||
auto l = Label::createWithSystemFont(strSubtitle.c_str(), "Arial", 18);
|
||||
l->setColor(Color3B(0, 0, 0));
|
||||
addChild(l, 1, 10001);
|
||||
l->setPosition(VisibleRect::center().x, VisibleRect::top().y - 60);
|
||||
}
|
||||
|
||||
// add menu
|
||||
backItem = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(ActionTimelineTestLayer::backCallback, this) );
|
||||
restartItem = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(ActionTimelineTestLayer::restartCallback, this) );
|
||||
nextItem = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(ActionTimelineTestLayer::nextCallback, this) );
|
||||
|
||||
Menu *menu = Menu::create(backItem, restartItem, nextItem, nullptr);
|
||||
|
||||
menu->setPosition(Point::ZERO);
|
||||
backItem->setPosition(VisibleRect::center().x - restartItem->getContentSize().width * 2, VisibleRect::bottom().y + restartItem->getContentSize().height / 2);
|
||||
restartItem->setPosition(VisibleRect::center().x, VisibleRect::bottom().y + restartItem->getContentSize().height / 2);
|
||||
nextItem->setPosition(VisibleRect::center().x + restartItem->getContentSize().width * 2, VisibleRect::bottom().y + restartItem->getContentSize().height / 2);
|
||||
|
||||
addChild(menu, 100);
|
||||
|
||||
setGLProgram(ShaderCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
|
||||
|
||||
}
|
||||
void ActionTimelineTestLayer::onExit()
|
||||
{
|
||||
removeAllChildren();
|
||||
|
||||
backItem = restartItem = nextItem = nullptr;
|
||||
|
||||
cocostudio::destroyCocosStudio();
|
||||
|
||||
Layer::onExit();
|
||||
TestCase::onExit();
|
||||
}
|
||||
|
||||
std::string ActionTimelineTestLayer::title() const
|
||||
std::string ActionTimelineBaseTest::title() const
|
||||
{
|
||||
return "Armature Test Bed";
|
||||
}
|
||||
std::string ActionTimelineTestLayer::subtitle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
void ActionTimelineTestLayer::restartCallback(Ref *pSender)
|
||||
{
|
||||
Scene *s = new (std::nothrow) ActionTimelineTestScene();
|
||||
s->addChild( RestartAnimationTest() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void ActionTimelineTestLayer::nextCallback(Ref *pSender)
|
||||
{
|
||||
Scene *s = new (std::nothrow) ActionTimelineTestScene();
|
||||
s->addChild( NextAnimationTest() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
void ActionTimelineTestLayer::backCallback(Ref *pSender)
|
||||
{
|
||||
Scene *s = new (std::nothrow) ActionTimelineTestScene();
|
||||
auto a = BackAnimationTest();
|
||||
s->addChild( a);
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TestActionTimeline
|
||||
void TestActionTimeline::onEnter()
|
||||
{
|
||||
ActionTimelineTestLayer::onEnter();
|
||||
ActionTimelineBaseTest::onEnter();
|
||||
|
||||
Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb");
|
||||
ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/DemoPlayer.csb");
|
||||
|
@ -232,7 +86,7 @@ std::string TestActionTimeline::title() const
|
|||
// TestActionTimeline
|
||||
void TestChangePlaySection::onEnter()
|
||||
{
|
||||
ActionTimelineTestLayer::onEnter();
|
||||
ActionTimelineBaseTest::onEnter();
|
||||
|
||||
Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb");
|
||||
action = CSLoader::createTimeline("ActionTimeline/DemoPlayer.csb");
|
||||
|
@ -271,7 +125,7 @@ void TestChangePlaySection::onTouchesEnded(const std::vector<Touch*>& touches, E
|
|||
// TestFrameEvent
|
||||
void TestTimelineFrameEvent::onEnter()
|
||||
{
|
||||
ActionTimelineTestLayer::onEnter();
|
||||
ActionTimelineBaseTest::onEnter();
|
||||
|
||||
Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb");
|
||||
ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/DemoPlayer.csb");
|
||||
|
@ -316,7 +170,7 @@ void TestTimelineFrameEvent::onFrameEvent(Frame* frame)
|
|||
// TestTimelinePerformance
|
||||
void TestTimelinePerformance::onEnter()
|
||||
{
|
||||
ActionTimelineTestLayer::onEnter();
|
||||
ActionTimelineBaseTest::onEnter();
|
||||
|
||||
for (int i = 0; i< 100; i++)
|
||||
{
|
||||
|
@ -340,7 +194,7 @@ std::string TestTimelinePerformance::title() const
|
|||
// TestTimelineAnimationList
|
||||
void TestTimelineAnimationList::onEnter()
|
||||
{
|
||||
ActionTimelineTestLayer::onEnter();
|
||||
ActionTimelineBaseTest::onEnter();
|
||||
Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb");
|
||||
ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/DemoPlayer.csb");
|
||||
cocostudio::timeline::AnimationInfo standinfo("stand", 0, 40);
|
||||
|
@ -365,7 +219,7 @@ std::string TestTimelineAnimationList::title() const
|
|||
//InnerActionFrame make InnerAction Play until action's duration or next InnerActionFrame
|
||||
void TestTimelineProjectNode::onEnter()
|
||||
{
|
||||
ActionTimelineTestLayer::onEnter();
|
||||
ActionTimelineBaseTest::onEnter();
|
||||
Node* node = CSLoader::createNode("ActionTimeline/TestAnimation.csb");
|
||||
ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/TestAnimation.csb");
|
||||
|
||||
|
@ -385,7 +239,7 @@ std::string TestTimelineProjectNode::title() const
|
|||
//InnerActionFrame make InnerAction Play until action's duration or next InnerActionFrame
|
||||
void TestProjectNodeForSimulator::onEnter()
|
||||
{
|
||||
ActionTimelineTestLayer::onEnter();
|
||||
ActionTimelineBaseTest::onEnter();
|
||||
Node* node = CSLoader::getInstance()->createNodeWithFlatBuffersForSimulator("ActionTimeline/TestAnimation.csd");
|
||||
ActionTimeline* action = cocostudio::timeline::ActionTimelineCache::getInstance()->createActionWithFlatBuffersForSimulator("ActionTimeline/TestAnimation.csd");
|
||||
|
||||
|
@ -411,7 +265,7 @@ std::string TestProjectNodeForSimulator::title() const
|
|||
//TestTimelineNodeLoadedCallback
|
||||
void TestTimelineNodeLoadedCallback::onEnter()
|
||||
{
|
||||
ActionTimelineTestLayer::onEnter();
|
||||
ActionTimelineBaseTest::onEnter();
|
||||
|
||||
Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb", CC_CALLBACK_1(TestTimelineNodeLoadedCallback::nodeLoadedCallback,
|
||||
this));
|
||||
|
@ -439,4 +293,4 @@ void TestTimelineNodeLoadedCallback::nodeLoadedCallback(cocos2d::Ref *sender)
|
|||
CCLOG("node name = %s", node->getName().c_str());
|
||||
CCLOG("node parent name = %s", node->getParent()->getName().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,117 +2,107 @@
|
|||
#define __ANIMATION_TEST_SCENE_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "../../VisibleRect.h"
|
||||
#include "../../testBasic.h"
|
||||
#include "../../BaseTest.h"
|
||||
#include "cocostudio/CocoStudio.h"
|
||||
|
||||
using namespace cocostudio::timeline;
|
||||
|
||||
|
||||
class ActionTimelineTestScene : public TestScene
|
||||
class CocoStudioActionTimelineTests : public TestSuite
|
||||
{
|
||||
public:
|
||||
ActionTimelineTestScene(bool bPortrait = false);
|
||||
|
||||
virtual void runThisTest();
|
||||
|
||||
// The CallBack for back to the main menu scene
|
||||
virtual void MainMenuCallback(Ref* pSender);
|
||||
public:
|
||||
CocoStudioActionTimelineTests();
|
||||
~CocoStudioActionTimelineTests();
|
||||
};
|
||||
|
||||
enum {
|
||||
TEST_ANIMATIONELEMENT = 0,
|
||||
TEST_CHANGE_PLAY_SECTION,
|
||||
// TEST_TIMELINE_FRAME_EVENT,
|
||||
TEST_TIMELINE_PERFORMACE,
|
||||
TEST_TIMELINEACTION_ANIMATIONLIST,
|
||||
TEST_TIMELINEPROJECTNODE,
|
||||
TEST_PROJECTNODEFORSIMALATOR,
|
||||
TEST_NODELOADEDCALLBACK,
|
||||
|
||||
TEST_ANIMATION_LAYER_COUNT
|
||||
};
|
||||
|
||||
class ActionTimelineTestLayer : public Layer
|
||||
class ActionTimelineBaseTest : public TestCase
|
||||
{
|
||||
public:
|
||||
virtual std::string title() const;
|
||||
virtual std::string subtitle() const;
|
||||
|
||||
virtual void restartCallback(Ref* pSender);
|
||||
virtual void nextCallback(Ref* pSender);
|
||||
virtual void backCallback(Ref* pSender);
|
||||
virtual bool init() override;
|
||||
|
||||
// overrides
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
|
||||
protected:
|
||||
MenuItemImage *restartItem;
|
||||
MenuItemImage *nextItem;
|
||||
MenuItemImage *backItem;
|
||||
};
|
||||
|
||||
|
||||
class TestActionTimeline : public ActionTimelineTestLayer
|
||||
class TestActionTimeline : public ActionTimelineBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestActionTimeline);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
class TestChangePlaySection : public ActionTimelineTestLayer
|
||||
class TestChangePlaySection : public ActionTimelineBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestChangePlaySection);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||
|
||||
protected:
|
||||
ActionTimeline* action;
|
||||
};
|
||||
|
||||
class TestTimelineFrameEvent : public ActionTimelineTestLayer
|
||||
class TestTimelineFrameEvent : public ActionTimelineBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestTimelineFrameEvent);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
|
||||
void onFrameEvent(Frame* frame);
|
||||
};
|
||||
|
||||
class TestTimelinePerformance : public ActionTimelineTestLayer
|
||||
class TestTimelinePerformance : public ActionTimelineBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestTimelinePerformance);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
class TestTimelineAnimationList : public ActionTimelineTestLayer
|
||||
class TestTimelineAnimationList : public ActionTimelineBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestTimelineAnimationList);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
class TestTimelineProjectNode : public ActionTimelineTestLayer
|
||||
class TestTimelineProjectNode : public ActionTimelineBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestTimelineProjectNode);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
class TestProjectNodeForSimulator : public ActionTimelineTestLayer
|
||||
class TestProjectNodeForSimulator : public ActionTimelineBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestProjectNodeForSimulator);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
class TestTimelineNodeLoadedCallback : public ActionTimelineTestLayer
|
||||
class TestTimelineNodeLoadedCallback : public ActionTimelineBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestTimelineNodeLoadedCallback);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
|
||||
|
|
|
@ -6,251 +6,75 @@
|
|||
using namespace cocos2d;
|
||||
using namespace cocostudio;
|
||||
|
||||
Layer *NextTest();
|
||||
Layer *BackTest();
|
||||
Layer *RestartTest();
|
||||
|
||||
static int s_nActionIdx = -1;
|
||||
|
||||
|
||||
Layer *CreateLayer(int index)
|
||||
CocoStudioArmatureTests::CocoStudioArmatureTests()
|
||||
{
|
||||
Layer *pLayer = nullptr;
|
||||
switch(index)
|
||||
{
|
||||
case TEST_ASYNCHRONOUS_LOADING:
|
||||
pLayer = new (std::nothrow) TestAsynchronousLoading();
|
||||
break;
|
||||
case TEST_DIRECT_LOADING:
|
||||
pLayer = new (std::nothrow) TestDirectLoading();
|
||||
break;
|
||||
case TEST_DRAGON_BONES_2_0:
|
||||
pLayer = new (std::nothrow) TestDragonBones20();
|
||||
break;
|
||||
case TEST_COCOSTUDIO_WITH_SKELETON:
|
||||
pLayer = new (std::nothrow) TestCSWithSkeleton();
|
||||
break;
|
||||
case TEST_PERFORMANCE:
|
||||
pLayer = new (std::nothrow) TestPerformance();
|
||||
break;
|
||||
// case TEST_PERFORMANCE_BATCHNODE:
|
||||
// pLayer = new (std::nothrow) TestPerformanceBatchNode();
|
||||
// break;
|
||||
case TEST_CHANGE_ZORDER:
|
||||
pLayer = new (std::nothrow) TestChangeZorder();
|
||||
break;
|
||||
case TEST_ANIMATION_EVENT:
|
||||
pLayer = new (std::nothrow) TestAnimationEvent();
|
||||
break;
|
||||
case TEST_FRAME_EVENT:
|
||||
pLayer = new (std::nothrow) TestFrameEvent();
|
||||
break;
|
||||
case TEST_PARTICLE_DISPLAY:
|
||||
pLayer = new (std::nothrow) TestParticleDisplay();
|
||||
break;
|
||||
case TEST_USE_DIFFERENT_PICTURE:
|
||||
pLayer = new (std::nothrow) TestUseMutiplePicture();
|
||||
break;
|
||||
case TEST_COLLIDER_DETECTOR:
|
||||
pLayer = new (std::nothrow) TestColliderDetector();
|
||||
break;
|
||||
case TEST_BOUDINGBOX:
|
||||
pLayer = new (std::nothrow) TestBoundingBox();
|
||||
break;
|
||||
case TEST_ANCHORPOINT:
|
||||
pLayer = new (std::nothrow) TestAnchorPoint();
|
||||
break;
|
||||
case TEST_ARMATURE_NESTING:
|
||||
pLayer = new (std::nothrow) TestArmatureNesting();
|
||||
break;
|
||||
case TEST_ARMATURE_NESTING_2:
|
||||
pLayer = new (std::nothrow) TestArmatureNesting2();
|
||||
break;
|
||||
case TEST_PLAY_SEVERAL_MOVEMENT:
|
||||
pLayer = new (std::nothrow) TestPlaySeveralMovement();
|
||||
break;
|
||||
case TEST_EASING:
|
||||
pLayer = new (std::nothrow) TestEasing();
|
||||
break;
|
||||
case TEST_CHANGE_ANIMATION_INTERNAL:
|
||||
pLayer = new (std::nothrow) TestChangeAnimationInternal();
|
||||
break;
|
||||
case TEST_DIRECT_FROM_BINARY:
|
||||
pLayer = new (std::nothrow) TestLoadFromBinary();
|
||||
break;
|
||||
case TEST_ARMATURE_NODE:
|
||||
pLayer = new (std::nothrow) TestArmatureNode();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return pLayer;
|
||||
ADD_TEST_CASE(TestAsynchronousLoading);
|
||||
ADD_TEST_CASE(TestDirectLoading);
|
||||
ADD_TEST_CASE(TestDragonBones20);
|
||||
ADD_TEST_CASE(TestCSWithSkeleton);
|
||||
ADD_TEST_CASE(TestPerformance);
|
||||
//ADD_TEST_CASE(TestPerformanceBatchNode);
|
||||
ADD_TEST_CASE(TestChangeZorder);
|
||||
ADD_TEST_CASE(TestAnimationEvent);
|
||||
ADD_TEST_CASE(TestFrameEvent);
|
||||
ADD_TEST_CASE(TestParticleDisplay);
|
||||
ADD_TEST_CASE(TestUseMutiplePicture);
|
||||
ADD_TEST_CASE(TestColliderDetector);
|
||||
ADD_TEST_CASE(TestBoundingBox);
|
||||
ADD_TEST_CASE(TestAnchorPoint);
|
||||
ADD_TEST_CASE(TestArmatureNesting);
|
||||
ADD_TEST_CASE(TestArmatureNesting2);
|
||||
ADD_TEST_CASE(TestPlaySeveralMovement);
|
||||
ADD_TEST_CASE(TestEasing);
|
||||
ADD_TEST_CASE(TestChangeAnimationInternal);
|
||||
ADD_TEST_CASE(TestLoadFromBinary);
|
||||
ADD_TEST_CASE(TestArmatureNode);
|
||||
}
|
||||
|
||||
|
||||
Layer *NextTest()
|
||||
CocoStudioArmatureTests::~CocoStudioArmatureTests()
|
||||
{
|
||||
++s_nActionIdx;
|
||||
s_nActionIdx = s_nActionIdx % TEST_LAYER_COUNT;
|
||||
|
||||
Layer *pLayer = CreateLayer(s_nActionIdx);
|
||||
pLayer->autorelease();
|
||||
|
||||
return pLayer;
|
||||
}
|
||||
|
||||
Layer *BackTest()
|
||||
{
|
||||
--s_nActionIdx;
|
||||
if( s_nActionIdx < 0 )
|
||||
s_nActionIdx += TEST_LAYER_COUNT;
|
||||
|
||||
Layer *pLayer = CreateLayer(s_nActionIdx);
|
||||
pLayer->autorelease();
|
||||
|
||||
return pLayer;
|
||||
}
|
||||
|
||||
Layer *RestartTest()
|
||||
{
|
||||
Layer *pLayer = CreateLayer(s_nActionIdx);
|
||||
pLayer->autorelease();
|
||||
|
||||
return pLayer;
|
||||
}
|
||||
|
||||
|
||||
ArmatureTestScene::ArmatureTestScene(bool bPortrait)
|
||||
{
|
||||
TestScene::init();
|
||||
|
||||
Sprite *bg = Sprite::create("armature/bg.jpg");
|
||||
bg->setPosition(VisibleRect::center());
|
||||
|
||||
float scaleX = VisibleRect::getVisibleRect().size.width / bg->getContentSize().width;
|
||||
float scaleY = VisibleRect::getVisibleRect().size.height / bg->getContentSize().height;
|
||||
|
||||
bg->setScaleX(scaleX);
|
||||
bg->setScaleY(scaleY);
|
||||
|
||||
addChild(bg);
|
||||
}
|
||||
void ArmatureTestScene::runThisTest()
|
||||
{
|
||||
|
||||
|
||||
s_nActionIdx = -1;
|
||||
addChild(NextTest());
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
void ArmatureTestScene::MainMenuCallback(Ref *pSender)
|
||||
{
|
||||
//TestScene::MainMenuCallback(pSender);
|
||||
|
||||
removeAllChildren();
|
||||
ArmatureDataManager::destroyInstance();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ArmatureTestLayer::onEnter()
|
||||
bool ArmatureBaseTest::init()
|
||||
{
|
||||
|
||||
Layer::onEnter();
|
||||
|
||||
// add title and subtitle
|
||||
std::string str = title();
|
||||
const char *pTitle = str.c_str();
|
||||
auto label = Label::createWithTTF(pTitle, "fonts/arial.ttf", 18);
|
||||
label->setColor(Color3B::BLACK);
|
||||
addChild(label, 1, 10000);
|
||||
label->setPosition(VisibleRect::center().x, VisibleRect::top().y - 30);
|
||||
|
||||
std::string strSubtitle = subtitle();
|
||||
if( ! strSubtitle.empty() )
|
||||
if (TestCase::init())
|
||||
{
|
||||
auto l = Label::createWithTTF(strSubtitle.c_str(), "fonts/arial.ttf", 18);
|
||||
l->setColor(Color3B::BLACK);
|
||||
addChild(l, 1, 10001);
|
||||
l->setPosition(VisibleRect::center().x, VisibleRect::top().y - 60);
|
||||
Sprite *bg = Sprite::create("armature/bg.jpg");
|
||||
bg->setPosition(VisibleRect::center());
|
||||
|
||||
float scaleX = VisibleRect::getVisibleRect().size.width / bg->getContentSize().width;
|
||||
float scaleY = VisibleRect::getVisibleRect().size.height / bg->getContentSize().height;
|
||||
|
||||
bg->setScaleX(scaleX);
|
||||
bg->setScaleY(scaleY);
|
||||
|
||||
addChild(bg);
|
||||
|
||||
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// add menu
|
||||
backItem = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(ArmatureTestLayer::backCallback, this) );
|
||||
restartItem = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(ArmatureTestLayer::restartCallback, this) );
|
||||
nextItem = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(ArmatureTestLayer::nextCallback, this) );
|
||||
|
||||
Menu *menu = Menu::create(backItem, restartItem, nextItem, nullptr);
|
||||
|
||||
menu->setPosition(Vec2::ZERO);
|
||||
backItem->setPosition(VisibleRect::center().x - restartItem->getContentSize().width * 2, VisibleRect::bottom().y + restartItem->getContentSize().height / 2);
|
||||
restartItem->setPosition(VisibleRect::center().x, VisibleRect::bottom().y + restartItem->getContentSize().height / 2);
|
||||
nextItem->setPosition(VisibleRect::center().x + restartItem->getContentSize().width * 2, VisibleRect::bottom().y + restartItem->getContentSize().height / 2);
|
||||
|
||||
addChild(menu, 100);
|
||||
|
||||
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
|
||||
|
||||
}
|
||||
void ArmatureTestLayer::onExit()
|
||||
{
|
||||
removeAllChildren();
|
||||
|
||||
backItem = restartItem = nextItem = nullptr;
|
||||
|
||||
cocostudio::destroyCocosStudio();
|
||||
|
||||
Layer::onExit();
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string ArmatureTestLayer::title() const
|
||||
std::string ArmatureBaseTest::title() const
|
||||
{
|
||||
return "Armature Test Bed";
|
||||
}
|
||||
std::string ArmatureTestLayer::subtitle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
void ArmatureTestLayer::restartCallback(Ref *pSender)
|
||||
{
|
||||
Scene *s = new (std::nothrow) ArmatureTestScene();
|
||||
s->addChild( RestartTest() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
void ArmatureTestLayer::nextCallback(Ref *pSender)
|
||||
{
|
||||
Scene *s = new (std::nothrow) ArmatureTestScene();
|
||||
s->addChild( NextTest() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
void ArmatureTestLayer::backCallback(Ref *pSender)
|
||||
{
|
||||
Scene *s = new (std::nothrow) ArmatureTestScene();
|
||||
s->addChild( BackTest() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void TestAsynchronousLoading::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
ArmatureBaseTest::onEnter();
|
||||
|
||||
//CCLOG("armature version : %s", armatureVersion());
|
||||
|
||||
backItem->setEnabled(false);
|
||||
restartItem->setEnabled(false);
|
||||
nextItem->setEnabled(false);
|
||||
_priorTestItem->setEnabled(false);
|
||||
_restartTestItem->setEnabled(false);
|
||||
_nextTestItem->setEnabled(false);
|
||||
|
||||
char pszPercent[255];
|
||||
sprintf(pszPercent, "%s %f", subtitle().c_str(), 0.0f);
|
||||
auto label = (Label *)getChildByTag(10001);
|
||||
label->setString(pszPercent);
|
||||
|
||||
_subtitleLabel->setString(pszPercent);
|
||||
|
||||
//! create a new thread to load data
|
||||
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/knight.png", "armature/knight.plist", "armature/knight.xml", this, CC_SCHEDULE_SELECTOR(TestAsynchronousLoading::dataLoaded));
|
||||
|
@ -275,33 +99,33 @@ std::string TestAsynchronousLoading::subtitle() const
|
|||
return "current percent : ";
|
||||
}
|
||||
|
||||
void TestAsynchronousLoading::restartCallback(Ref* pSender)
|
||||
void TestAsynchronousLoading::restartTestCallback(Ref* pSender)
|
||||
{
|
||||
ArmatureDataManager::destroyInstance();
|
||||
ArmatureTestLayer::restartCallback(pSender);
|
||||
ArmatureBaseTest::restartTestCallback(pSender);
|
||||
}
|
||||
|
||||
void TestAsynchronousLoading::dataLoaded(float percent)
|
||||
{
|
||||
auto label = (Label *)getChildByTag(10001);
|
||||
if (label)
|
||||
if (_subtitleLabel)
|
||||
{
|
||||
char pszPercent[255];
|
||||
sprintf(pszPercent, "%s %f", subtitle().c_str(), percent * 100);
|
||||
label->setString(pszPercent);
|
||||
_subtitleLabel->setString(pszPercent);
|
||||
}
|
||||
|
||||
if (percent >= 1 && backItem && restartItem && nextItem)
|
||||
if (percent >= 1)
|
||||
{
|
||||
backItem->setEnabled(true);
|
||||
restartItem->setEnabled(true);
|
||||
nextItem->setEnabled(true);
|
||||
_priorTestItem->setEnabled(true);
|
||||
_restartTestItem->setEnabled(true);
|
||||
_nextTestItem->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TestDirectLoading::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
ArmatureBaseTest::onEnter();
|
||||
|
||||
// remove sigle resource
|
||||
ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/bear.ExportJson");
|
||||
|
@ -322,7 +146,7 @@ std::string TestDirectLoading::title() const
|
|||
|
||||
void TestCSWithSkeleton::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
ArmatureBaseTest::onEnter();
|
||||
Armature *armature = nullptr;
|
||||
armature = Armature::create("Cowboy");
|
||||
armature->getAnimation()->playWithIndex(0);
|
||||
|
@ -337,12 +161,9 @@ std::string TestCSWithSkeleton::title() const
|
|||
return "Test Export From CocoStudio With Skeleton Effect";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void TestDragonBones20::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
ArmatureBaseTest::onEnter();
|
||||
|
||||
Armature *armature = nullptr;
|
||||
armature = Armature::create("Dragon");
|
||||
|
@ -358,8 +179,6 @@ std::string TestDragonBones20::title() const
|
|||
return "Test Export From DragonBones version 2.0";
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define ArmaturePerformanceTag 20000
|
||||
|
||||
TestPerformance::~TestPerformance()
|
||||
|
@ -367,7 +186,7 @@ TestPerformance::~TestPerformance()
|
|||
}
|
||||
void TestPerformance::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
ArmatureBaseTest::onEnter();
|
||||
|
||||
|
||||
MenuItemFont::setFontSize(65);
|
||||
|
@ -441,8 +260,7 @@ void TestPerformance::refreshTitle()
|
|||
{
|
||||
char pszCount[255];
|
||||
sprintf(pszCount, "%s %i", subtitle().c_str(), armatureCount);
|
||||
auto label = (Label *)getChildByTag(10001);
|
||||
label->setString(pszCount);
|
||||
_subtitleLabel->setString(pszCount);
|
||||
}
|
||||
|
||||
|
||||
|
@ -469,7 +287,7 @@ void TestPerformanceBatchNode::removeArmatureFromParent(int tag)
|
|||
|
||||
void TestChangeZorder::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
ArmatureBaseTest::onEnter();
|
||||
|
||||
Armature *armature = nullptr;
|
||||
currentTag = -1;
|
||||
|
@ -514,12 +332,9 @@ void TestChangeZorder::changeZorder(float dt)
|
|||
currentTag = currentTag % 3;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void TestAnimationEvent::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
ArmatureBaseTest::onEnter();
|
||||
armature = Armature::create("Cowboy");
|
||||
armature->getAnimation()->play("Fire");
|
||||
armature->setScaleX(-0.24f);
|
||||
|
@ -568,13 +383,11 @@ void TestAnimationEvent::callback2()
|
|||
armature->getAnimation()->play("Fire", 10);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define FRAME_EVENT_ACTION_TAG 10000
|
||||
|
||||
void TestFrameEvent::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
ArmatureBaseTest::onEnter();
|
||||
_gridNode = NodeGrid::create();
|
||||
Armature *armature = Armature::create("HeroAnimation");
|
||||
armature->getAnimation()->play("attack");
|
||||
|
@ -615,11 +428,9 @@ void TestFrameEvent::checkAction(float dt)
|
|||
_gridNode->setGrid(nullptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TestParticleDisplay::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
ArmatureBaseTest::onEnter();
|
||||
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesEnded = CC_CALLBACK_2(TestParticleDisplay::onTouchesEnded, this);
|
||||
|
@ -657,7 +468,7 @@ void TestParticleDisplay::onEnter()
|
|||
|
||||
void TestParticleDisplay::onExit()
|
||||
{
|
||||
ArmatureTestLayer::onExit();
|
||||
ArmatureBaseTest::onExit();
|
||||
}
|
||||
|
||||
std::string TestParticleDisplay::title() const
|
||||
|
@ -679,7 +490,7 @@ void TestParticleDisplay::onTouchesEnded(const std::vector<Touch*>& touches, Eve
|
|||
|
||||
void TestUseMutiplePicture::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
ArmatureBaseTest::onEnter();
|
||||
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesEnded = CC_CALLBACK_2(TestUseMutiplePicture::onTouchesEnded, this);
|
||||
|
@ -715,7 +526,7 @@ void TestUseMutiplePicture::onEnter()
|
|||
|
||||
void TestUseMutiplePicture::onExit()
|
||||
{
|
||||
ArmatureTestLayer::onExit();
|
||||
ArmatureBaseTest::onExit();
|
||||
}
|
||||
|
||||
std::string TestUseMutiplePicture::title() const
|
||||
|
@ -740,7 +551,7 @@ TestColliderDetector::~TestColliderDetector()
|
|||
}
|
||||
void TestColliderDetector::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
ArmatureBaseTest::onEnter();
|
||||
|
||||
scheduleUpdate();
|
||||
|
||||
|
@ -852,7 +663,7 @@ void TestColliderDetector::onExit()
|
|||
CC_SAFE_DELETE(listener);
|
||||
CC_SAFE_DELETE(debugDraw);
|
||||
|
||||
ArmatureTestLayer::onExit();
|
||||
ArmatureBaseTest::onExit();
|
||||
}
|
||||
void TestColliderDetector::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
||||
{
|
||||
|
@ -978,7 +789,7 @@ void TestColliderDetector::onExit()
|
|||
|
||||
cpSpaceFree(space);
|
||||
|
||||
ArmatureTestLayer::onExit();
|
||||
ArmatureBaseTest::onExit();
|
||||
}
|
||||
|
||||
void TestColliderDetector::update(float delta)
|
||||
|
@ -1112,12 +923,9 @@ void TestColliderDetector::draw(Renderer *renderer, const Mat4 &transform, uint3
|
|||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void TestBoundingBox::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
ArmatureBaseTest::onEnter();
|
||||
|
||||
armature = Armature::create("Cowboy");
|
||||
armature->getAnimation()->playWithIndex(0);
|
||||
|
@ -1144,7 +952,7 @@ void TestBoundingBox::draw(Renderer *renderer, const Mat4 &transform, uint32_t f
|
|||
|
||||
void TestAnchorPoint::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
ArmatureBaseTest::onEnter();
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
|
@ -1169,7 +977,7 @@ std::string TestAnchorPoint::title() const
|
|||
|
||||
void TestArmatureNesting::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
ArmatureBaseTest::onEnter();
|
||||
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesEnded = CC_CALLBACK_2(TestArmatureNesting::onTouchesEnded, this);
|
||||
|
@ -1187,7 +995,7 @@ void TestArmatureNesting::onEnter()
|
|||
|
||||
void TestArmatureNesting::onExit()
|
||||
{
|
||||
ArmatureTestLayer::onExit();
|
||||
ArmatureBaseTest::onExit();
|
||||
}
|
||||
|
||||
std::string TestArmatureNesting::title() const
|
||||
|
@ -1224,7 +1032,7 @@ Hero *Hero::create(const char *name)
|
|||
|
||||
Hero::Hero()
|
||||
: m_pMount(nullptr)
|
||||
, m_pLayer(nullptr)
|
||||
, _scene(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1241,8 +1049,7 @@ void Hero::changeMount(Armature *armature)
|
|||
|
||||
//Set position to current position
|
||||
setPosition(m_pMount->getPosition());
|
||||
//Add to layer
|
||||
m_pLayer->addChild(this);
|
||||
_scene->addChild(this);
|
||||
|
||||
release();
|
||||
|
||||
|
@ -1286,7 +1093,7 @@ void Hero::playWithIndex(int index)
|
|||
|
||||
void TestArmatureNesting2::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
ArmatureBaseTest::onEnter();
|
||||
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesEnded = CC_CALLBACK_2(TestArmatureNesting2::onTouchesEnded, this);
|
||||
|
@ -1306,7 +1113,7 @@ void TestArmatureNesting2::onEnter()
|
|||
|
||||
//Create a hero
|
||||
hero = Hero::create("hero");
|
||||
hero->setLayer(this);
|
||||
hero->setScene(this);
|
||||
hero->playWithIndex(0);
|
||||
hero->setPosition(VisibleRect::left().x + 20, VisibleRect::left().y);
|
||||
addChild(hero);
|
||||
|
@ -1321,7 +1128,7 @@ void TestArmatureNesting2::onEnter()
|
|||
}
|
||||
void TestArmatureNesting2::onExit()
|
||||
{
|
||||
ArmatureTestLayer::onExit();
|
||||
ArmatureBaseTest::onExit();
|
||||
}
|
||||
std::string TestArmatureNesting2::title() const
|
||||
{
|
||||
|
@ -1390,11 +1197,7 @@ Armature * TestArmatureNesting2::createMount(const char *name, Vec2 position)
|
|||
|
||||
void TestPlaySeveralMovement::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesEnded = CC_CALLBACK_2(TestPlaySeveralMovement::onTouchesEnded, this);
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||
ArmatureBaseTest::onEnter();
|
||||
|
||||
std::string name[] = {"Walk", "FireMax", "Fire"};
|
||||
std::vector<std::string> names(name, name+3);
|
||||
|
@ -1423,12 +1226,7 @@ std::string TestPlaySeveralMovement::subtitle()const
|
|||
|
||||
void TestEasing::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesEnded = CC_CALLBACK_2(TestPlaySeveralMovement::onTouchesEnded, this);
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||
|
||||
ArmatureBaseTest::onEnter();
|
||||
animationID = 0;
|
||||
|
||||
armature = Armature::create("testEasing");
|
||||
|
@ -1460,17 +1258,12 @@ void TestEasing::onTouchesEnded(const std::vector<Touch*>& touches, Event* event
|
|||
void TestEasing::updateSubTitle()
|
||||
{
|
||||
std::string str = subtitle() + armature->getAnimation()->getCurrentMovementID();
|
||||
auto label = (Label *)getChildByTag(10001);
|
||||
label->setString(str.c_str());
|
||||
_subtitleLabel->setString(str.c_str());
|
||||
}
|
||||
|
||||
void TestChangeAnimationInternal::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesEnded = CC_CALLBACK_2(TestPlaySeveralMovement::onTouchesEnded, this);
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||
ArmatureBaseTest::onEnter();
|
||||
|
||||
Armature *armature = nullptr;
|
||||
armature = Armature::create("Cowboy");
|
||||
|
@ -1483,7 +1276,7 @@ void TestChangeAnimationInternal::onEnter()
|
|||
void TestChangeAnimationInternal::onExit()
|
||||
{
|
||||
Director::getInstance()->setAnimationInterval(1/60.0f);
|
||||
ArmatureTestLayer::onExit();
|
||||
ArmatureBaseTest::onExit();
|
||||
}
|
||||
std::string TestChangeAnimationInternal::title() const
|
||||
{
|
||||
|
@ -1519,7 +1312,7 @@ const char* TestLoadFromBinary::m_armatureNames[BINARYFILECOUNT] ={"bear","hors
|
|||
|
||||
void TestLoadFromBinary::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
ArmatureBaseTest::onEnter();
|
||||
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesEnded = CC_CALLBACK_2(TestLoadFromBinary::onTouchesEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||
|
@ -1592,34 +1385,30 @@ void TestLoadFromBinary::onTouchesEnded(const std::vector<Touch*>& touches, Even
|
|||
|
||||
void TestLoadFromBinary::dataLoaded( float percent )
|
||||
{
|
||||
Label *label = (Label *)getChildByTag(10001);
|
||||
if (label)
|
||||
if (_subtitleLabel)
|
||||
{
|
||||
char pszPercent[255];
|
||||
sprintf(pszPercent, "%s %f", "Asynchronous loading: ", percent * 100);
|
||||
label->setString(pszPercent);
|
||||
_subtitleLabel->setString(pszPercent);
|
||||
}
|
||||
|
||||
if (percent >= 1)
|
||||
{
|
||||
label->setString("Touch to change armature");
|
||||
_subtitleLabel->setString("Touch to change armature");
|
||||
m_armatureIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//TestArmatureNode
|
||||
|
||||
void TestArmatureNode::onEnter()
|
||||
{
|
||||
ArmatureTestLayer::onEnter();
|
||||
ArmatureBaseTest::onEnter();
|
||||
|
||||
auto node = CSLoader::createNode("TestArmatureNode.csb");
|
||||
addChild(node);
|
||||
}
|
||||
|
||||
|
||||
std::string TestArmatureNode::title() const
|
||||
{
|
||||
return "Test Armature Node";
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
|
||||
#include "cocos2d.h"
|
||||
#include "extensions/cocos-ext.h"
|
||||
#include "../../VisibleRect.h"
|
||||
#include "../../testBasic.h"
|
||||
#include "../../BaseTest.h"
|
||||
#include "cocostudio/CocoStudio.h"
|
||||
|
||||
#if ENABLE_PHYSICS_BOX2D_DETECT
|
||||
|
@ -14,100 +13,71 @@
|
|||
#include "chipmunk.h"
|
||||
#endif
|
||||
|
||||
class ArmatureTestScene : public TestScene
|
||||
class CocoStudioArmatureTests : public TestSuite
|
||||
{
|
||||
public:
|
||||
ArmatureTestScene(bool bPortrait = false);
|
||||
public:
|
||||
CocoStudioArmatureTests();
|
||||
~CocoStudioArmatureTests();
|
||||
|
||||
virtual void runThisTest();
|
||||
private:
|
||||
|
||||
// The CallBack for back to the main menu scene
|
||||
virtual void MainMenuCallback(Ref* pSender);
|
||||
};
|
||||
|
||||
enum {
|
||||
TEST_ASYNCHRONOUS_LOADING = 0,
|
||||
TEST_DIRECT_LOADING,
|
||||
TEST_COCOSTUDIO_WITH_SKELETON,
|
||||
TEST_DRAGON_BONES_2_0,
|
||||
TEST_PERFORMANCE,
|
||||
// TEST_PERFORMANCE_BATCHNODE,
|
||||
TEST_CHANGE_ZORDER,
|
||||
TEST_ANIMATION_EVENT,
|
||||
TEST_FRAME_EVENT,
|
||||
TEST_PARTICLE_DISPLAY,
|
||||
TEST_USE_DIFFERENT_PICTURE,
|
||||
TEST_COLLIDER_DETECTOR,
|
||||
TEST_BOUDINGBOX,
|
||||
TEST_ANCHORPOINT,
|
||||
TEST_ARMATURE_NESTING,
|
||||
TEST_ARMATURE_NESTING_2,
|
||||
TEST_PLAY_SEVERAL_MOVEMENT,
|
||||
TEST_EASING,
|
||||
TEST_CHANGE_ANIMATION_INTERNAL,
|
||||
TEST_DIRECT_FROM_BINARY,
|
||||
TEST_ARMATURE_NODE,
|
||||
|
||||
TEST_LAYER_COUNT
|
||||
};
|
||||
|
||||
class ArmatureTestLayer : public Layer
|
||||
class ArmatureBaseTest : public TestCase
|
||||
{
|
||||
public:
|
||||
virtual std::string title() const;
|
||||
virtual std::string subtitle() const;
|
||||
|
||||
virtual void restartCallback(Ref* pSender);
|
||||
virtual void nextCallback(Ref* pSender);
|
||||
virtual void backCallback(Ref* pSender);
|
||||
|
||||
// overrides
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
virtual bool init() override;
|
||||
|
||||
protected:
|
||||
MenuItemImage *restartItem;
|
||||
MenuItemImage *nextItem;
|
||||
MenuItemImage *backItem;
|
||||
};
|
||||
|
||||
|
||||
class TestAsynchronousLoading : public ArmatureTestLayer
|
||||
class TestAsynchronousLoading : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestAsynchronousLoading);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void restartCallback(Ref* pSender);
|
||||
virtual void restartTestCallback(Ref* pSender) override;
|
||||
|
||||
void dataLoaded(float percent);
|
||||
};
|
||||
|
||||
class TestDirectLoading : public ArmatureTestLayer
|
||||
class TestDirectLoading : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestDirectLoading);
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
class TestCSWithSkeleton : public ArmatureTestLayer
|
||||
class TestCSWithSkeleton : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestCSWithSkeleton);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
|
||||
class TestDragonBones20 : public ArmatureTestLayer
|
||||
class TestDragonBones20 : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestDragonBones20);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
|
||||
class TestPerformance : public ArmatureTestLayer
|
||||
class TestPerformance : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestPerformance);
|
||||
|
||||
~TestPerformance();
|
||||
|
||||
virtual void onEnter() override;
|
||||
|
@ -130,6 +100,9 @@ public:
|
|||
|
||||
class TestPerformanceBatchNode : public TestPerformance
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestPerformanceBatchNode);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
virtual void addArmatureToParent(cocostudio::Armature *armature);
|
||||
|
@ -138,8 +111,11 @@ class TestPerformanceBatchNode : public TestPerformance
|
|||
cocostudio::BatchNode *batchNode;
|
||||
};
|
||||
|
||||
class TestChangeZorder : public ArmatureTestLayer
|
||||
class TestChangeZorder : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestChangeZorder);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
void changeZorder(float dt);
|
||||
|
@ -148,9 +124,10 @@ class TestChangeZorder : public ArmatureTestLayer
|
|||
};
|
||||
|
||||
|
||||
class TestAnimationEvent : public ArmatureTestLayer
|
||||
class TestAnimationEvent : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestAnimationEvent);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
|
@ -162,9 +139,11 @@ public:
|
|||
};
|
||||
|
||||
|
||||
class TestFrameEvent : public ArmatureTestLayer
|
||||
class TestFrameEvent : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestFrameEvent);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
void onFrameEvent(cocostudio::Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex);
|
||||
|
@ -174,40 +153,46 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
class TestUseMutiplePicture : public ArmatureTestLayer
|
||||
class TestUseMutiplePicture : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestUseMutiplePicture);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||
|
||||
int displayIndex;
|
||||
cocostudio::Armature *armature;
|
||||
};
|
||||
|
||||
class TestParticleDisplay : public ArmatureTestLayer
|
||||
class TestParticleDisplay : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestParticleDisplay);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||
|
||||
int animationID;
|
||||
cocostudio::Armature *armature;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#if ENABLE_PHYSICS_BOX2D_DETECT
|
||||
|
||||
class ContactListener;
|
||||
|
||||
class TestColliderDetector : public ArmatureTestLayer
|
||||
class TestColliderDetector : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestColliderDetector);
|
||||
|
||||
~TestColliderDetector();
|
||||
|
||||
virtual void onEnter() override;
|
||||
|
@ -235,9 +220,11 @@ public:
|
|||
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||
|
||||
|
||||
class TestColliderDetector : public ArmatureTestLayer
|
||||
class TestColliderDetector : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestColliderDetector);
|
||||
|
||||
~TestColliderDetector();
|
||||
|
||||
virtual void onEnter() override;
|
||||
|
@ -264,9 +251,11 @@ public:
|
|||
void destroyCPBody(cpBody *body);
|
||||
};
|
||||
#elif ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||
class TestColliderDetector : public ArmatureTestLayer
|
||||
class TestColliderDetector : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestColliderDetector);
|
||||
|
||||
~TestColliderDetector();
|
||||
|
||||
virtual void onEnter() override;
|
||||
|
@ -286,12 +275,11 @@ public:
|
|||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class TestBoundingBox : public ArmatureTestLayer
|
||||
class TestBoundingBox : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestBoundingBox);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
|
||||
|
@ -303,20 +291,24 @@ protected:
|
|||
DrawNode* _drawNode;
|
||||
};
|
||||
|
||||
class TestAnchorPoint : public ArmatureTestLayer
|
||||
class TestAnchorPoint : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestAnchorPoint);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
class TestArmatureNesting : public ArmatureTestLayer
|
||||
class TestArmatureNesting : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestArmatureNesting);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
virtual std::string title() const override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||
|
||||
cocostudio::Armature *armature;
|
||||
int weaponIndex;
|
||||
|
@ -332,17 +324,19 @@ public:
|
|||
virtual void playWithIndex(int index);
|
||||
|
||||
CC_SYNTHESIZE(cocostudio::Armature*, m_pMount, Mount);
|
||||
CC_SYNTHESIZE(cocos2d::Layer*, m_pLayer, Layer);
|
||||
CC_SYNTHESIZE(cocos2d::Scene*, _scene, Scene);
|
||||
};
|
||||
|
||||
class TestArmatureNesting2 : public ArmatureTestLayer
|
||||
class TestArmatureNesting2 : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestArmatureNesting2);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||
|
||||
void changeMountCallback(Ref* pSender);
|
||||
virtual cocostudio::Armature *createMount(const char *name, Vec2 position);
|
||||
|
@ -358,50 +352,58 @@ private:
|
|||
bool touchedMenu;
|
||||
};
|
||||
|
||||
class TestPlaySeveralMovement : public ArmatureTestLayer
|
||||
class TestPlaySeveralMovement : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestPlaySeveralMovement);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
|
||||
class TestEasing : public ArmatureTestLayer
|
||||
class TestEasing : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestEasing);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||
void updateSubTitle();
|
||||
|
||||
int animationID;
|
||||
cocostudio::Armature *armature;
|
||||
};
|
||||
|
||||
class TestChangeAnimationInternal : public ArmatureTestLayer
|
||||
class TestChangeAnimationInternal : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestChangeAnimationInternal);
|
||||
|
||||
virtual void onEnter()override;
|
||||
virtual void onExit() override;
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||
};
|
||||
|
||||
|
||||
#define BINARYFILECOUNT 6
|
||||
class TestLoadFromBinary : public ArmatureTestLayer
|
||||
class TestLoadFromBinary : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestLoadFromBinary);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||
|
||||
|
||||
void dataLoaded(float percent);
|
||||
|
@ -413,9 +415,11 @@ private:
|
|||
int m_armatureIndex; // index of sync loaded armature, default -1 is none
|
||||
};
|
||||
|
||||
class TestArmatureNode : public ArmatureTestLayer
|
||||
class TestArmatureNode : public ArmatureBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TestArmatureNode);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
|
|
@ -8,61 +8,35 @@ using namespace cocos2d;
|
|||
using namespace cocos2d::extension;
|
||||
using namespace cocostudio;
|
||||
|
||||
ComponentsTestLayer::~ComponentsTestLayer()
|
||||
CocoStudioComponentsTests::CocoStudioComponentsTests()
|
||||
{
|
||||
ADD_TEST_CASE(CocoStudioComponentsTest);
|
||||
}
|
||||
|
||||
ComponentsTestLayer::ComponentsTestLayer()
|
||||
bool CocoStudioComponentsTest::init()
|
||||
{
|
||||
}
|
||||
if (TestCase::init())
|
||||
{
|
||||
auto bg = LayerColor::create(Color4B(255, 255, 255, 255));
|
||||
addChild(bg);
|
||||
|
||||
Scene* ComponentsTestLayer::scene()
|
||||
{
|
||||
Scene * scene = nullptr;
|
||||
do
|
||||
{
|
||||
// 'scene' is an autorelease object
|
||||
scene = Scene::create();
|
||||
CC_BREAK_IF(! scene);
|
||||
|
||||
// 'layer' is an autorelease object
|
||||
auto layer = ComponentsTestLayer::create();
|
||||
CC_BREAK_IF(! layer);
|
||||
|
||||
// add layer as a child to scene
|
||||
scene->addChild(layer);
|
||||
} while (0);
|
||||
|
||||
// return the scene
|
||||
return scene;
|
||||
}
|
||||
|
||||
// on "init" you need to initialize your instance
|
||||
bool ComponentsTestLayer::init()
|
||||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(! LayerColor::initWithColor( Color4B(255,255,255,255) ) );
|
||||
|
||||
auto root = createGameScene();
|
||||
CC_BREAK_IF(!root);
|
||||
this->addChild(root, 0, 1);
|
||||
|
||||
root->getChildByTag(1)->addComponent(ComAudio::create());
|
||||
root->getChildByTag(1)->addComponent(PlayerController::create());
|
||||
|
||||
root->getChildByTag(1)->addComponent(PlayerController::create());
|
||||
|
||||
root->addComponent(ComAudio::create());
|
||||
root->addComponent(ComAttribute::create());
|
||||
root->addComponent(SceneController::create());
|
||||
|
||||
bRet = true;
|
||||
} while (0);
|
||||
return true;
|
||||
}
|
||||
|
||||
return bRet;
|
||||
return false;
|
||||
}
|
||||
|
||||
cocos2d::Node* ComponentsTestLayer::createGameScene()
|
||||
cocos2d::Node* CocoStudioComponentsTest::createGameScene()
|
||||
{
|
||||
Node *root = nullptr;
|
||||
do
|
||||
|
@ -79,26 +53,8 @@ cocos2d::Node* ComponentsTestLayer::createGameScene()
|
|||
root = cocos2d::Node::create();
|
||||
root->addChild(player, 1, 1);
|
||||
|
||||
|
||||
auto itemBack = MenuItemFont::create("Back", [](Ref* sender){
|
||||
auto scene = new (std::nothrow) ExtensionsTestScene();
|
||||
scene->runThisTest();
|
||||
scene->release();
|
||||
});
|
||||
|
||||
itemBack->setColor(Color3B(0, 0, 0));
|
||||
itemBack->setPosition(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25);
|
||||
auto menuBack = Menu::create(itemBack, nullptr);
|
||||
menuBack->setPosition(Vec2::ZERO);
|
||||
addChild(menuBack);
|
||||
|
||||
}while (0);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
void runComponentsTestLayerTest()
|
||||
{
|
||||
auto scene = ComponentsTestLayer::scene();
|
||||
Director::getInstance()->replaceScene(scene);
|
||||
}
|
||||
|
|
|
@ -3,26 +3,17 @@
|
|||
|
||||
#include "cocos2d.h"
|
||||
#include "extensions/cocos-ext.h"
|
||||
#include "BaseTest.h"
|
||||
|
||||
void runComponentsTestLayerTest();
|
||||
DEFINE_TEST_SUITE(CocoStudioComponentsTests);
|
||||
|
||||
class ComponentsTestLayer : public cocos2d::LayerColor
|
||||
class CocoStudioComponentsTest : public TestCase
|
||||
{
|
||||
public:
|
||||
ComponentsTestLayer();
|
||||
~ComponentsTestLayer();
|
||||
CREATE_FUNC(CocoStudioComponentsTest);
|
||||
|
||||
// Here's a difference. Method 'init' in cocos2d-x returns bool,
|
||||
// instead of returning 'id' in cocos2d-iphone
|
||||
virtual bool init() override;
|
||||
|
||||
// there's no 'id' in cpp, so we recommand to return the exactly class pointer
|
||||
static cocos2d::Scene* scene();
|
||||
virtual bool init() override;
|
||||
|
||||
// implement the "static node()" method manually
|
||||
CREATE_FUNC(ComponentsTestLayer);
|
||||
|
||||
// init scene
|
||||
cocos2d::Node* createGameScene();
|
||||
};
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ using namespace cocos2d;
|
|||
|
||||
bool GameOverScene::init()
|
||||
{
|
||||
if( Scene::init() )
|
||||
if( TestCase::init() )
|
||||
{
|
||||
this->_layer = GameOverLayer::create();
|
||||
this->_layer->retain();
|
||||
|
@ -70,19 +70,6 @@ bool GameOverLayer::init()
|
|||
DelayTime::create(3),
|
||||
CallFunc::create(CC_CALLBACK_0(GameOverLayer::gameOverDone, this)),
|
||||
nullptr));
|
||||
|
||||
|
||||
auto itemBack = MenuItemFont::create("Back", [](Ref* sender){
|
||||
auto scene = new (std::nothrow) ExtensionsTestScene();
|
||||
scene->runThisTest();
|
||||
scene->release();
|
||||
});
|
||||
|
||||
itemBack->setColor(Color3B(0, 0, 0));
|
||||
itemBack->setPosition(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25);
|
||||
auto menuBack = Menu::create(itemBack, nullptr);
|
||||
menuBack->setPosition(Vec2::ZERO);
|
||||
addChild(menuBack);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -94,7 +81,11 @@ bool GameOverLayer::init()
|
|||
|
||||
void GameOverLayer::gameOverDone()
|
||||
{
|
||||
Director::getInstance()->replaceScene( ComponentsTestLayer::scene() );
|
||||
auto director = Director::getInstance();
|
||||
auto newScene = CocoStudioComponentsTest::create();
|
||||
auto gameoverScene = (GameOverScene*)director->getRunningScene();
|
||||
newScene->setTestSuite(gameoverScene->getTestSuite());
|
||||
director->replaceScene(newScene);
|
||||
}
|
||||
|
||||
GameOverLayer::~GameOverLayer()
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define _GAME_OVER_SCENE_H_
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "BaseTest.h"
|
||||
|
||||
class GameOverLayer : public cocos2d::LayerColor
|
||||
{
|
||||
|
@ -16,13 +17,15 @@ public:
|
|||
CC_SYNTHESIZE_READONLY(cocos2d::Label*, _label, Label);
|
||||
};
|
||||
|
||||
class GameOverScene : public cocos2d::Scene
|
||||
class GameOverScene : public TestCase
|
||||
{
|
||||
public:
|
||||
GameOverScene():_layer(nullptr) {};
|
||||
~GameOverScene();
|
||||
bool init();
|
||||
CREATE_FUNC(GameOverScene);
|
||||
|
||||
GameOverScene():_layer(nullptr) {}
|
||||
~GameOverScene();
|
||||
|
||||
virtual bool init() override;
|
||||
|
||||
CC_SYNTHESIZE_READONLY(GameOverLayer*, _layer, Layer);
|
||||
};
|
||||
|
|
|
@ -79,8 +79,13 @@ void SceneController::spriteMoveFinished(Node* sender)
|
|||
if (sprite->getTag() == 2) // target
|
||||
{
|
||||
_targets.eraseObject(sprite);
|
||||
|
||||
auto director = Director::getInstance();
|
||||
auto gameOverScene = GameOverScene::create();
|
||||
gameOverScene->getLayer()->getLabel()->setString("You Lose :[");
|
||||
auto currScene = (CocoStudioComponentsTest*)director->getRunningScene();
|
||||
gameOverScene->setTestSuite(currScene->getTestSuite());
|
||||
|
||||
Director::getInstance()->replaceScene(gameOverScene);
|
||||
}
|
||||
else if (sprite->getTag() == 3)
|
||||
|
@ -99,8 +104,11 @@ void SceneController::increaseKillCount()
|
|||
|
||||
if (nProjectilesDestroyed >= 5)
|
||||
{
|
||||
auto director = Director::getInstance();
|
||||
auto gameOverScene = GameOverScene::create();
|
||||
gameOverScene->getLayer()->getLabel()->setString("You Win!");
|
||||
auto currScene = (CocoStudioComponentsTest*)director->getRunningScene();
|
||||
gameOverScene->setTestSuite(currScene->getTestSuite());
|
||||
Director::getInstance()->replaceScene(gameOverScene);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
class SceneController : public cocostudio::ComController
|
||||
{
|
||||
protected:
|
||||
SceneController(void);
|
||||
virtual ~SceneController(void);
|
||||
SceneController();
|
||||
virtual ~SceneController();
|
||||
|
||||
public:
|
||||
virtual bool init() override;
|
||||
|
@ -17,7 +17,7 @@ public:
|
|||
virtual void onExit() override;
|
||||
virtual void update(float delta) override;
|
||||
|
||||
static SceneController* create(void);
|
||||
static SceneController* create();
|
||||
|
||||
public:
|
||||
cocos2d::Vector<cocos2d::Node*>& getTargets() {return _targets;};
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include "extensions/cocos-ext.h"
|
||||
#include "../ExtensionsTest.h"
|
||||
#include "SceneEditorTest.h"
|
||||
|
@ -11,202 +10,47 @@ using namespace cocos2d;
|
|||
using namespace cocostudio;
|
||||
using namespace ui;
|
||||
|
||||
Layer *Next();
|
||||
Layer *Back();
|
||||
Layer *Restart();
|
||||
|
||||
static int s_nIdx = -1;
|
||||
|
||||
Layer *createTests(int index)
|
||||
CocoStudioSceneEditTests::CocoStudioSceneEditTests()
|
||||
{
|
||||
Layer *layer = nullptr;
|
||||
switch(index)
|
||||
ADD_TEST_CASE(LoadSceneEdtiorFileTest);
|
||||
ADD_TEST_CASE(SpriteComponentTest);
|
||||
ADD_TEST_CASE(ArmatureComponentTest);
|
||||
ADD_TEST_CASE(UIComponentTest);
|
||||
ADD_TEST_CASE(TmxMapComponentTest);
|
||||
ADD_TEST_CASE(ParticleComponentTest);
|
||||
ADD_TEST_CASE(EffectComponentTest);
|
||||
ADD_TEST_CASE(BackgroundComponentTest);
|
||||
ADD_TEST_CASE(AttributeComponentTest);
|
||||
ADD_TEST_CASE(TriggerTest);
|
||||
}
|
||||
|
||||
const char* SceneEditorTestBase::_loadtypeStr[2] = {"change to load \nwith binary file","change to load \nwith json file"};
|
||||
bool SceneEditorTestBase::init()
|
||||
{
|
||||
if (TestCase::init())
|
||||
{
|
||||
case TEST_LOADSCENEEDITORFILE:
|
||||
layer = new (std::nothrow) LoadSceneEdtiorFileTest();
|
||||
break;
|
||||
case TEST_SPIRTECOMPONENT:
|
||||
layer = new (std::nothrow) SpriteComponentTest();
|
||||
break;
|
||||
case TEST_ARMATURECOMPONENT:
|
||||
layer = new (std::nothrow) ArmatureComponentTest();
|
||||
break;
|
||||
case TEST_UICOMPONENT:
|
||||
layer = new (std::nothrow) UIComponentTest();
|
||||
break;
|
||||
case TEST_TMXMAPCOMPONENT:
|
||||
layer = new (std::nothrow) TmxMapComponentTest();
|
||||
break;
|
||||
case TEST_PARTICLECOMPONENT:
|
||||
layer = new (std::nothrow) ParticleComponentTest();
|
||||
break;
|
||||
case TEST_EFEECTCOMPONENT:
|
||||
layer = new (std::nothrow) EffectComponentTest();
|
||||
break;
|
||||
case TEST_BACKGROUNDCOMPONENT:
|
||||
layer = new (std::nothrow) BackgroundComponentTest();
|
||||
break;
|
||||
case TEST_ATTRIBUTECOMPONENT:
|
||||
layer = new (std::nothrow) AttributeComponentTest();
|
||||
break;
|
||||
case TEST_TRIGGER:
|
||||
layer = new (std::nothrow) TriggerTest();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
_isCsbLoad = false;
|
||||
_loadtypelb = cocos2d::Label::createWithSystemFont(_loadtypeStr[0], "Arial", 12);
|
||||
// #endif
|
||||
MenuItemLabel* itemlb = CCMenuItemLabel::create(_loadtypelb, CC_CALLBACK_1(SceneEditorTestBase::changeLoadTypeCallback, this));
|
||||
Menu* loadtypemenu = CCMenu::create(itemlb, nullptr);
|
||||
loadtypemenu->setPosition(Point(VisibleRect::rightTop().x - 50, VisibleRect::rightTop().y - 20));
|
||||
addChild(loadtypemenu, 100);
|
||||
|
||||
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
|
||||
|
||||
return true;
|
||||
}
|
||||
return layer;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Layer *Next()
|
||||
{
|
||||
++s_nIdx;
|
||||
s_nIdx = s_nIdx % TEST_SCENEEDITOR_COUNT;
|
||||
|
||||
Layer *layer = createTests(s_nIdx);
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
Layer *Back()
|
||||
{
|
||||
--s_nIdx;
|
||||
if( s_nIdx < 0 )
|
||||
s_nIdx += TEST_SCENEEDITOR_COUNT;
|
||||
|
||||
Layer *layer = createTests(s_nIdx);
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
Layer *Restart()
|
||||
{
|
||||
Layer *layer = createTests(s_nIdx);
|
||||
layer->autorelease();
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
SceneEditorTestScene::SceneEditorTestScene(bool bPortrait)
|
||||
{
|
||||
TestScene::init();
|
||||
}
|
||||
|
||||
void SceneEditorTestScene::runThisTest()
|
||||
{
|
||||
s_nIdx = -1;
|
||||
addChild(Next());
|
||||
CCDirector::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
||||
void SceneEditorTestScene::MainMenuCallback(Ref *pSender)
|
||||
{
|
||||
removeAllChildren();
|
||||
}
|
||||
|
||||
const char* SceneEditorTestLayer::_loadtypeStr[2] = {"change to load \nwith binary file","change to load \nwith json file"};
|
||||
void SceneEditorTestLayer::onEnter()
|
||||
{
|
||||
CCLayer::onEnter();
|
||||
|
||||
// add title and subtitle
|
||||
std::string str = title();
|
||||
const char *pTitle = str.c_str();
|
||||
auto label = Label::createWithTTF(pTitle, "fonts/arial.ttf", 18);
|
||||
label->setTextColor(Color4B::WHITE);
|
||||
addChild(label, 1, 10000);
|
||||
label->setPosition( Vec2(VisibleRect::center().x, VisibleRect::top().y - 30) );
|
||||
|
||||
std::string strSubtitle = subtitle();
|
||||
if( ! strSubtitle.empty() )
|
||||
{
|
||||
auto l = Label::createWithTTF(strSubtitle.c_str(), "fonts/arial.ttf", 18);
|
||||
l->setTextColor(Color4B::BLACK);
|
||||
addChild(l, 1, 10001);
|
||||
l->setPosition(Vec2(VisibleRect::center().x, VisibleRect::top().y - 60) );
|
||||
}
|
||||
_isCsbLoad = false;
|
||||
_loadtypelb = cocos2d::Label::createWithSystemFont(_loadtypeStr[0], "Arial", 12);
|
||||
// #endif
|
||||
MenuItemLabel* itemlb = CCMenuItemLabel::create(_loadtypelb, CC_CALLBACK_1(SceneEditorTestLayer::changeLoadTypeCallback, this));
|
||||
Menu* loadtypemenu = CCMenu::create(itemlb, nullptr);
|
||||
loadtypemenu->setPosition(Point(VisibleRect::rightTop().x -50,VisibleRect::rightTop().y -20));
|
||||
addChild(loadtypemenu,100);
|
||||
|
||||
// add menu
|
||||
backItem = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(SceneEditorTestLayer::backCallback, this) );
|
||||
restartItem = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(SceneEditorTestLayer::restartCallback, this) );
|
||||
nextItem = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(SceneEditorTestLayer::nextCallback, this) );
|
||||
|
||||
|
||||
Menu *menu = Menu::create(backItem, restartItem, nextItem, nullptr);
|
||||
|
||||
float fScale = 0.5f;
|
||||
|
||||
menu->setPosition(Vec2(0, 0));
|
||||
backItem->setPosition(Vec2(VisibleRect::center().x - restartItem->getContentSize().width * 2 * fScale, VisibleRect::bottom().y + restartItem->getContentSize().height / 2));
|
||||
backItem->setScale(fScale);
|
||||
|
||||
restartItem->setPosition(Vec2(VisibleRect::center().x, VisibleRect::bottom().y + restartItem->getContentSize().height / 2));
|
||||
restartItem->setScale(fScale);
|
||||
|
||||
nextItem->setPosition(Vec2(VisibleRect::center().x + restartItem->getContentSize().width * 2 * fScale, VisibleRect::bottom().y + restartItem->getContentSize().height / 2));
|
||||
nextItem->setScale(fScale);
|
||||
|
||||
addChild(menu, 100);
|
||||
|
||||
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
|
||||
}
|
||||
|
||||
void SceneEditorTestLayer::onExit()
|
||||
{
|
||||
removeAllChildren();
|
||||
backItem = restartItem = nextItem = nullptr;
|
||||
Layer::onExit();
|
||||
}
|
||||
|
||||
std::string SceneEditorTestLayer::title()
|
||||
std::string SceneEditorTestBase::title() const
|
||||
{
|
||||
return "SceneReader Test LoadSceneEditorFile";
|
||||
}
|
||||
|
||||
std::string SceneEditorTestLayer::subtitle()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
void SceneEditorTestLayer::restartCallback(Ref *pSender)
|
||||
{
|
||||
Scene *s = new (std::nothrow) SceneEditorTestScene();
|
||||
s->addChild(Restart());
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void SceneEditorTestLayer::nextCallback(Ref *pSender)
|
||||
{
|
||||
Scene *s = new (std::nothrow) SceneEditorTestScene();
|
||||
s->addChild(Next());
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void SceneEditorTestLayer::backCallback(Ref *pSender)
|
||||
{
|
||||
Scene *s = new (std::nothrow) SceneEditorTestScene();
|
||||
s->addChild(Back());
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void SceneEditorTestLayer::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
||||
{
|
||||
Layer::draw(renderer, transform, flags);
|
||||
}
|
||||
|
||||
void SceneEditorTestLayer::changeLoadTypeCallback(cocos2d::Ref *pSender)
|
||||
void SceneEditorTestBase::changeLoadTypeCallback(cocos2d::Ref *pSender)
|
||||
{
|
||||
_isCsbLoad = !_isCsbLoad;
|
||||
_loadtypelb->setString(_loadtypeStr[(int)_isCsbLoad]);
|
||||
|
@ -226,7 +70,7 @@ void SceneEditorTestLayer::changeLoadTypeCallback(cocos2d::Ref *pSender)
|
|||
}
|
||||
}
|
||||
|
||||
void SceneEditorTestLayer::loadFileChangeHelper(std::string& filePathName)
|
||||
void SceneEditorTestBase::loadFileChangeHelper(std::string& filePathName)
|
||||
{
|
||||
std::string::size_type n = filePathName.find_last_of(".");
|
||||
if(n == std::string::npos)
|
||||
|
@ -248,14 +92,14 @@ LoadSceneEdtiorFileTest::~LoadSceneEdtiorFileTest()
|
|||
|
||||
}
|
||||
|
||||
std::string LoadSceneEdtiorFileTest::title()
|
||||
std::string LoadSceneEdtiorFileTest::title() const
|
||||
{
|
||||
return "loadSceneEdtiorFile Test";
|
||||
}
|
||||
|
||||
void LoadSceneEdtiorFileTest::onEnter()
|
||||
{
|
||||
SceneEditorTestLayer::onEnter();
|
||||
SceneEditorTestBase::onEnter();
|
||||
do
|
||||
{
|
||||
Node *root = createGameScene();
|
||||
|
@ -270,7 +114,7 @@ void LoadSceneEdtiorFileTest::onExit()
|
|||
SceneReader::destroyInstance();
|
||||
ActionManagerEx::destroyInstance();
|
||||
GUIReader::destroyInstance();
|
||||
SceneEditorTestLayer::onExit();
|
||||
SceneEditorTestBase::onExit();
|
||||
}
|
||||
|
||||
|
||||
|
@ -302,14 +146,14 @@ SpriteComponentTest::~SpriteComponentTest()
|
|||
|
||||
}
|
||||
|
||||
std::string SpriteComponentTest::title()
|
||||
std::string SpriteComponentTest::title() const
|
||||
{
|
||||
return "Sprite Component Test";
|
||||
}
|
||||
|
||||
void SpriteComponentTest::onEnter()
|
||||
{
|
||||
SceneEditorTestLayer::onEnter();
|
||||
SceneEditorTestBase::onEnter();
|
||||
do
|
||||
{
|
||||
Node *root = createGameScene();
|
||||
|
@ -324,7 +168,7 @@ void SpriteComponentTest::onExit()
|
|||
SceneReader::destroyInstance();
|
||||
ActionManagerEx::destroyInstance();
|
||||
GUIReader::destroyInstance();
|
||||
SceneEditorTestLayer::onExit();
|
||||
SceneEditorTestBase::onExit();
|
||||
}
|
||||
|
||||
cocos2d::Node* SpriteComponentTest::createGameScene()
|
||||
|
@ -364,14 +208,14 @@ ArmatureComponentTest::~ArmatureComponentTest()
|
|||
|
||||
}
|
||||
|
||||
std::string ArmatureComponentTest::title()
|
||||
std::string ArmatureComponentTest::title() const
|
||||
{
|
||||
return "Armature Component Test";
|
||||
}
|
||||
|
||||
void ArmatureComponentTest::onEnter()
|
||||
{
|
||||
SceneEditorTestLayer::onEnter();
|
||||
SceneEditorTestBase::onEnter();
|
||||
do
|
||||
{
|
||||
Node *root = createGameScene();
|
||||
|
@ -386,7 +230,7 @@ void ArmatureComponentTest::onExit()
|
|||
SceneReader::destroyInstance();
|
||||
ActionManagerEx::destroyInstance();
|
||||
GUIReader::destroyInstance();
|
||||
SceneEditorTestLayer::onExit();
|
||||
SceneEditorTestBase::onExit();
|
||||
}
|
||||
|
||||
cocos2d::Node* ArmatureComponentTest::createGameScene()
|
||||
|
@ -420,14 +264,14 @@ UIComponentTest::~UIComponentTest()
|
|||
{
|
||||
}
|
||||
|
||||
std::string UIComponentTest::title()
|
||||
std::string UIComponentTest::title() const
|
||||
{
|
||||
return "UI Component Test";
|
||||
}
|
||||
|
||||
void UIComponentTest::onEnter()
|
||||
{
|
||||
SceneEditorTestLayer::onEnter();
|
||||
SceneEditorTestBase::onEnter();
|
||||
do
|
||||
{
|
||||
Node *root = createGameScene();
|
||||
|
@ -442,7 +286,7 @@ void UIComponentTest::onExit()
|
|||
SceneReader::destroyInstance();
|
||||
ActionManagerEx::destroyInstance();
|
||||
GUIReader::destroyInstance();
|
||||
SceneEditorTestLayer::onExit();
|
||||
SceneEditorTestBase::onExit();
|
||||
}
|
||||
|
||||
cocos2d::Node* UIComponentTest::createGameScene()
|
||||
|
@ -495,14 +339,14 @@ TmxMapComponentTest::~TmxMapComponentTest()
|
|||
|
||||
}
|
||||
|
||||
std::string TmxMapComponentTest::title()
|
||||
std::string TmxMapComponentTest::title() const
|
||||
{
|
||||
return "TmxMap Component Test";
|
||||
}
|
||||
|
||||
void TmxMapComponentTest::onEnter()
|
||||
{
|
||||
SceneEditorTestLayer::onEnter();
|
||||
SceneEditorTestBase::onEnter();
|
||||
do
|
||||
{
|
||||
Node *root = createGameScene();
|
||||
|
@ -517,7 +361,7 @@ void TmxMapComponentTest::onExit()
|
|||
SceneReader::destroyInstance();
|
||||
ActionManagerEx::destroyInstance();
|
||||
GUIReader::destroyInstance();
|
||||
SceneEditorTestLayer::onExit();
|
||||
SceneEditorTestBase::onExit();
|
||||
}
|
||||
|
||||
cocos2d::Node* TmxMapComponentTest::createGameScene()
|
||||
|
@ -557,14 +401,14 @@ ParticleComponentTest::~ParticleComponentTest()
|
|||
{
|
||||
}
|
||||
|
||||
std::string ParticleComponentTest::title()
|
||||
std::string ParticleComponentTest::title() const
|
||||
{
|
||||
return "Particle Component Test";
|
||||
}
|
||||
|
||||
void ParticleComponentTest::onEnter()
|
||||
{
|
||||
SceneEditorTestLayer::onEnter();
|
||||
SceneEditorTestBase::onEnter();
|
||||
do
|
||||
{
|
||||
Node *root = createGameScene();
|
||||
|
@ -579,7 +423,7 @@ void ParticleComponentTest::onExit()
|
|||
SceneReader::destroyInstance();
|
||||
ActionManagerEx::destroyInstance();
|
||||
GUIReader::destroyInstance();
|
||||
SceneEditorTestLayer::onExit();
|
||||
SceneEditorTestBase::onExit();
|
||||
}
|
||||
|
||||
cocos2d::Node* ParticleComponentTest::createGameScene()
|
||||
|
@ -612,14 +456,14 @@ EffectComponentTest::~EffectComponentTest()
|
|||
{
|
||||
}
|
||||
|
||||
std::string EffectComponentTest::title()
|
||||
std::string EffectComponentTest::title() const
|
||||
{
|
||||
return "Effect Component Test";
|
||||
}
|
||||
|
||||
void EffectComponentTest::onEnter()
|
||||
{
|
||||
SceneEditorTestLayer::onEnter();
|
||||
SceneEditorTestBase::onEnter();
|
||||
do
|
||||
{
|
||||
Node *root = createGameScene();
|
||||
|
@ -634,7 +478,7 @@ void EffectComponentTest::onExit()
|
|||
SceneReader::destroyInstance();
|
||||
ActionManagerEx::destroyInstance();
|
||||
GUIReader::destroyInstance();
|
||||
SceneEditorTestLayer::onExit();
|
||||
SceneEditorTestBase::onExit();
|
||||
}
|
||||
|
||||
cocos2d::Node* EffectComponentTest::createGameScene()
|
||||
|
@ -679,14 +523,14 @@ BackgroundComponentTest::~BackgroundComponentTest()
|
|||
{
|
||||
}
|
||||
|
||||
std::string BackgroundComponentTest::title()
|
||||
std::string BackgroundComponentTest::title() const
|
||||
{
|
||||
return "Background Component Test";
|
||||
}
|
||||
|
||||
void BackgroundComponentTest::onEnter()
|
||||
{
|
||||
SceneEditorTestLayer::onEnter();
|
||||
SceneEditorTestBase::onEnter();
|
||||
do
|
||||
{
|
||||
Node *root = createGameScene();
|
||||
|
@ -701,7 +545,7 @@ void BackgroundComponentTest::onExit()
|
|||
SceneReader::destroyInstance();
|
||||
ActionManagerEx::destroyInstance();
|
||||
GUIReader::destroyInstance();
|
||||
SceneEditorTestLayer::onExit();
|
||||
SceneEditorTestBase::onExit();
|
||||
}
|
||||
|
||||
cocos2d::Node* BackgroundComponentTest::createGameScene()
|
||||
|
@ -732,14 +576,14 @@ AttributeComponentTest::~AttributeComponentTest()
|
|||
{
|
||||
}
|
||||
|
||||
std::string AttributeComponentTest::title()
|
||||
std::string AttributeComponentTest::title() const
|
||||
{
|
||||
return "Attribute Component Test";
|
||||
}
|
||||
|
||||
void AttributeComponentTest::onEnter()
|
||||
{
|
||||
SceneEditorTestLayer::onEnter();
|
||||
SceneEditorTestBase::onEnter();
|
||||
do
|
||||
{
|
||||
Node *root = createGameScene();
|
||||
|
@ -755,7 +599,7 @@ void AttributeComponentTest::onExit()
|
|||
SceneReader::destroyInstance();
|
||||
ActionManagerEx::destroyInstance();
|
||||
GUIReader::destroyInstance();
|
||||
SceneEditorTestLayer::onExit();
|
||||
SceneEditorTestBase::onExit();
|
||||
}
|
||||
|
||||
bool AttributeComponentTest::initData()
|
||||
|
@ -799,7 +643,7 @@ TriggerTest::~TriggerTest()
|
|||
{
|
||||
}
|
||||
|
||||
std::string TriggerTest::title()
|
||||
std::string TriggerTest::title() const
|
||||
{
|
||||
return "Trigger Test";
|
||||
}
|
||||
|
@ -808,17 +652,17 @@ std::string TriggerTest::title()
|
|||
// on "init" you need to initialize your instance
|
||||
void TriggerTest::onEnter()
|
||||
{
|
||||
SceneEditorTestLayer::onEnter();
|
||||
SceneEditorTestBase::onEnter();
|
||||
Node *root = createGameScene();
|
||||
this->addChild(root, 0, 1);
|
||||
this->schedule(CC_SCHEDULE_SELECTOR(TriggerTest::gameLogic));
|
||||
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
||||
auto listener = EventListenerTouchOneByOne::create();
|
||||
listener->setSwallowTouches(true);
|
||||
listener->onTouchBegan = CC_CALLBACK_2(SceneEditorTestLayer::onTouchBegan, this);
|
||||
listener->onTouchMoved = CC_CALLBACK_2(SceneEditorTestLayer::onTouchMoved, this);
|
||||
listener->onTouchEnded = CC_CALLBACK_2(SceneEditorTestLayer::onTouchEnded, this);
|
||||
listener->onTouchCancelled = CC_CALLBACK_2(SceneEditorTestLayer::onTouchCancelled, this);
|
||||
listener->onTouchBegan = CC_CALLBACK_2(TriggerTest::onTouchBegan, this);
|
||||
listener->onTouchMoved = CC_CALLBACK_2(TriggerTest::onTouchMoved, this);
|
||||
listener->onTouchEnded = CC_CALLBACK_2(TriggerTest::onTouchEnded, this);
|
||||
listener->onTouchCancelled = CC_CALLBACK_2(TriggerTest::onTouchCancelled, this);
|
||||
dispatcher->addEventListenerWithFixedPriority(listener, 1);
|
||||
_touchListener = listener;
|
||||
}
|
||||
|
@ -835,7 +679,7 @@ void TriggerTest::onExit()
|
|||
SceneReader::destroyInstance();
|
||||
ActionManagerEx::destroyInstance();
|
||||
GUIReader::destroyInstance();
|
||||
SceneEditorTestLayer::onExit();
|
||||
SceneEditorTestBase::onExit();
|
||||
}
|
||||
|
||||
bool TriggerTest::onTouchBegan(Touch *touch, Event *unused_event)
|
||||
|
|
|
@ -4,46 +4,16 @@
|
|||
#include "cocos2d.h"
|
||||
#include "extensions/cocos-ext.h"
|
||||
#include "cocostudio/CocoStudio.h"
|
||||
#include "BaseTest.h"
|
||||
|
||||
class SceneEditorTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
SceneEditorTestScene(bool bPortrait = false);
|
||||
DEFINE_TEST_SUITE(CocoStudioSceneEditTests);
|
||||
|
||||
virtual void runThisTest();
|
||||
|
||||
// The CallBack for back to the main menu scene
|
||||
virtual void MainMenuCallback(cocos2d::Ref* pSender);
|
||||
};
|
||||
|
||||
enum {
|
||||
TEST_LOADSCENEEDITORFILE = 0,
|
||||
TEST_SPIRTECOMPONENT,
|
||||
TEST_ARMATURECOMPONENT,
|
||||
TEST_UICOMPONENT,
|
||||
TEST_TMXMAPCOMPONENT,
|
||||
TEST_PARTICLECOMPONENT,
|
||||
TEST_EFEECTCOMPONENT,
|
||||
TEST_BACKGROUNDCOMPONENT,
|
||||
TEST_ATTRIBUTECOMPONENT,
|
||||
TEST_TRIGGER,
|
||||
TEST_SCENEEDITOR_COUNT
|
||||
};
|
||||
|
||||
class SceneEditorTestLayer : public cocos2d::Layer
|
||||
class SceneEditorTestBase : public TestCase
|
||||
{
|
||||
public:
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
virtual bool init() override;
|
||||
|
||||
virtual std::string title();
|
||||
virtual std::string subtitle();
|
||||
|
||||
virtual void restartCallback(cocos2d::Ref* pSender);
|
||||
virtual void nextCallback(cocos2d::Ref* pSender);
|
||||
virtual void backCallback(cocos2d::Ref* pSender);
|
||||
|
||||
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
|
||||
virtual std::string title() const override;
|
||||
|
||||
protected:
|
||||
MenuItemImage *restartItem;
|
||||
|
@ -65,13 +35,15 @@ protected:
|
|||
std::string _filePath;
|
||||
};
|
||||
|
||||
class LoadSceneEdtiorFileTest : public SceneEditorTestLayer
|
||||
class LoadSceneEdtiorFileTest : public SceneEditorTestBase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(LoadSceneEdtiorFileTest);
|
||||
|
||||
LoadSceneEdtiorFileTest();
|
||||
~LoadSceneEdtiorFileTest();
|
||||
|
||||
virtual std::string title();
|
||||
virtual std::string title() const override;
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
cocos2d::Node* createGameScene();
|
||||
|
@ -80,13 +52,15 @@ private:
|
|||
};
|
||||
|
||||
|
||||
class SpriteComponentTest : public SceneEditorTestLayer
|
||||
class SpriteComponentTest : public SceneEditorTestBase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SpriteComponentTest);
|
||||
|
||||
SpriteComponentTest();
|
||||
~SpriteComponentTest();
|
||||
|
||||
virtual std::string title();
|
||||
virtual std::string title() const override;
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
cocos2d::Node* createGameScene();
|
||||
|
@ -95,13 +69,15 @@ private:
|
|||
void defaultPlay();
|
||||
};
|
||||
|
||||
class ArmatureComponentTest : public SceneEditorTestLayer
|
||||
class ArmatureComponentTest : public SceneEditorTestBase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(ArmatureComponentTest);
|
||||
|
||||
ArmatureComponentTest();
|
||||
~ArmatureComponentTest();
|
||||
|
||||
virtual std::string title();
|
||||
virtual std::string title() const override;
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
cocos2d::Node* createGameScene();
|
||||
|
@ -110,13 +86,15 @@ private:
|
|||
void defaultPlay();
|
||||
};
|
||||
|
||||
class UIComponentTest : public SceneEditorTestLayer
|
||||
class UIComponentTest : public SceneEditorTestBase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(UIComponentTest);
|
||||
|
||||
UIComponentTest();
|
||||
~UIComponentTest();
|
||||
|
||||
virtual std::string title();
|
||||
virtual std::string title() const override;
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
cocos2d::Node* createGameScene();
|
||||
|
@ -125,13 +103,15 @@ private:
|
|||
void defaultPlay();
|
||||
};
|
||||
|
||||
class TmxMapComponentTest : public SceneEditorTestLayer
|
||||
class TmxMapComponentTest : public SceneEditorTestBase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TmxMapComponentTest);
|
||||
|
||||
TmxMapComponentTest();
|
||||
~TmxMapComponentTest();
|
||||
|
||||
virtual std::string title();
|
||||
virtual std::string title() const override;
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
cocos2d::Node* createGameScene();
|
||||
|
@ -140,13 +120,15 @@ private:
|
|||
|
||||
};
|
||||
|
||||
class ParticleComponentTest : public SceneEditorTestLayer
|
||||
class ParticleComponentTest : public SceneEditorTestBase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(ParticleComponentTest);
|
||||
|
||||
ParticleComponentTest();
|
||||
~ParticleComponentTest();
|
||||
|
||||
virtual std::string title();
|
||||
virtual std::string title() const override;
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
cocos2d::Node* createGameScene();
|
||||
|
@ -154,13 +136,15 @@ protected:
|
|||
void defaultPlay();
|
||||
};
|
||||
|
||||
class EffectComponentTest : public SceneEditorTestLayer
|
||||
class EffectComponentTest : public SceneEditorTestBase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(EffectComponentTest);
|
||||
|
||||
EffectComponentTest();
|
||||
~EffectComponentTest();
|
||||
|
||||
virtual std::string title();
|
||||
virtual std::string title() const override;
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
cocos2d::Node* createGameScene();
|
||||
|
@ -170,13 +154,15 @@ private:
|
|||
|
||||
};
|
||||
|
||||
class BackgroundComponentTest : public SceneEditorTestLayer
|
||||
class BackgroundComponentTest : public SceneEditorTestBase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(BackgroundComponentTest);
|
||||
|
||||
BackgroundComponentTest();
|
||||
~BackgroundComponentTest();
|
||||
|
||||
virtual std::string title();
|
||||
virtual std::string title() const override;
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
cocos2d::Node* createGameScene();
|
||||
|
@ -184,13 +170,15 @@ private:
|
|||
void defaultPlay();
|
||||
};
|
||||
|
||||
class AttributeComponentTest : public SceneEditorTestLayer
|
||||
class AttributeComponentTest : public SceneEditorTestBase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(AttributeComponentTest);
|
||||
|
||||
AttributeComponentTest();
|
||||
~AttributeComponentTest();
|
||||
|
||||
virtual std::string title();
|
||||
virtual std::string title() const override;
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
bool initData();
|
||||
|
@ -200,13 +188,15 @@ private:
|
|||
void defaultPlay();
|
||||
};
|
||||
|
||||
class TriggerTest : public SceneEditorTestLayer
|
||||
class TriggerTest : public SceneEditorTestBase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(TriggerTest);
|
||||
|
||||
TriggerTest();
|
||||
~TriggerTest();
|
||||
|
||||
virtual std::string title();
|
||||
virtual std::string title() const override;
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
|
||||
|
|
|
@ -30,46 +30,33 @@ USING_NS_CC;
|
|||
USING_NS_CC_EXT;
|
||||
using namespace cocosbuilder;
|
||||
|
||||
void CocosBuilderTestScene::runThisTest() {
|
||||
/* Create an autorelease NodeLoaderLibrary. */
|
||||
NodeLoaderLibrary * ccNodeLoaderLibrary = NodeLoaderLibrary::newDefaultNodeLoaderLibrary();
|
||||
|
||||
ccNodeLoaderLibrary->registerNodeLoader("HelloCocosBuilderLayer", HelloCocosBuilderLayerLoader::loader());
|
||||
|
||||
/* Create an autorelease CCBReader. */
|
||||
cocosbuilder::CCBReader * ccbReader = new cocosbuilder::CCBReader(ccNodeLoaderLibrary);
|
||||
|
||||
/* Read a ccbi file. */
|
||||
auto node = ccbReader->readNodeGraphFromFile("ccb/HelloCocosBuilder.ccbi", this);
|
||||
|
||||
ccbReader->release();
|
||||
|
||||
if(node != nullptr) {
|
||||
this->addChild(node);
|
||||
}
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
CocosBuilderTests::CocosBuilderTests()
|
||||
{
|
||||
ADD_TEST_CASE(CocosBuilderTestScene);
|
||||
}
|
||||
|
||||
bool CocosBuilderTestScene::init() {
|
||||
if (TestCase::init())
|
||||
{
|
||||
/* Create an autorelease NodeLoaderLibrary. */
|
||||
auto nodeLoaderLibrary = NodeLoaderLibrary::newDefaultNodeLoaderLibrary();
|
||||
|
||||
//void CocosBuilderTestScene::runThisTest() {
|
||||
// auto ccbiReaderLayer = CCBIReaderLayer::node();
|
||||
//
|
||||
// /* Create an autorelease NodeLoaderLibrary. */
|
||||
// NodeLoaderLibrary * ccNodeLoaderLibrary = NodeLoaderLibrary::newDefaultNodeLoaderLibrary();
|
||||
//
|
||||
// /* Create an autorelease CCBReader. */
|
||||
// CCBReader * ccbReader = new (std::nothrow) CCBReader(ccNodeLoaderLibrary, ccbiReaderLayer, ccbiReaderLayer);
|
||||
// ccbReader->autorelease();
|
||||
//
|
||||
// /* Read a ccbi file. */
|
||||
// auto node = ccbReader->readNodeGraphFromFile("ccb/simple/pub/", "ccb/test.ccbi", ccbiReaderLayer);
|
||||
//
|
||||
// if(node != nullptr) {
|
||||
// ccbiReaderLayer->addChild(node);
|
||||
// }
|
||||
//
|
||||
// this->addChild(ccbiReaderLayer);
|
||||
//
|
||||
// Director::getInstance()->replaceScene(this);
|
||||
//}
|
||||
nodeLoaderLibrary->registerNodeLoader("HelloCocosBuilderLayer", HelloCocosBuilderLayerLoader::loader());
|
||||
|
||||
/* Create an autorelease CCBReader. */
|
||||
cocosbuilder::CCBReader * ccbReader = new cocosbuilder::CCBReader(nodeLoaderLibrary);
|
||||
|
||||
/* Read a ccbi file. */
|
||||
auto node = ccbReader->readNodeGraphFromFile("ccb/HelloCocosBuilder.ccbi", this);
|
||||
|
||||
ccbReader->release();
|
||||
|
||||
if (node != nullptr) {
|
||||
this->addChild(node);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
#ifndef _CCBIREADER_TEST_H_
|
||||
#define _CCBIREADER_TEST_H_
|
||||
|
||||
#include "../../testBasic.h"
|
||||
#include "../../BaseTest.h"
|
||||
|
||||
class CocosBuilderTestScene : public TestScene {
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
DEFINE_TEST_SUITE(CocosBuilderTests);
|
||||
|
||||
class CocosBuilderTestScene : public TestCase {
|
||||
public:
|
||||
CREATE_FUNC(CocosBuilderTestScene);
|
||||
|
||||
virtual bool init() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -33,19 +33,23 @@ USING_NS_CC_EXT;
|
|||
class ControlButtonTest_HelloVariableSize : public ControlScene
|
||||
{
|
||||
public:
|
||||
bool init();
|
||||
CREATE_FUNC(ControlButtonTest_HelloVariableSize);
|
||||
|
||||
virtual bool init() override;
|
||||
/** Creates and return a button with a default background and title color. */
|
||||
ControlButton *standardButtonWithTitle(const char * title);
|
||||
|
||||
CONTROL_SCENE_CREATE_FUNC(ControlButtonTest_HelloVariableSize)
|
||||
};
|
||||
|
||||
class ControlButtonTest_Event : public ControlScene
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(ControlButtonTest_Event);
|
||||
|
||||
ControlButtonTest_Event();
|
||||
~ControlButtonTest_Event();
|
||||
bool init();
|
||||
|
||||
virtual bool init() override;
|
||||
|
||||
void touchDownAction(Ref *sender, Control::EventType controlEvent);
|
||||
void touchDragInsideAction(Ref *sender, Control::EventType controlEvent);
|
||||
void touchDragOutsideAction(Ref *sender, Control::EventType controlEvent);
|
||||
|
@ -58,16 +62,15 @@ public:
|
|||
protected:
|
||||
CC_SYNTHESIZE_RETAIN(Label *, _displayValueLabel, DisplayValueLabel)
|
||||
CC_SYNTHESIZE_RETAIN(Label *, _displayBitmaskLabel, DisplayBitmaskLabel)
|
||||
CONTROL_SCENE_CREATE_FUNC(ControlButtonTest_Event)
|
||||
|
||||
};
|
||||
|
||||
|
||||
class ControlButtonTest_Styling : public ControlScene
|
||||
{
|
||||
public:
|
||||
bool init();
|
||||
virtual bool init() override;
|
||||
ControlButton *standardButtonWithTitle(const char *title);
|
||||
CONTROL_SCENE_CREATE_FUNC(ControlButtonTest_Styling)
|
||||
CREATE_FUNC(ControlButtonTest_Styling);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,28 +1,3 @@
|
|||
/*
|
||||
* ControlColourPickerTest.m
|
||||
*
|
||||
* Copyright (c) 2012 Yannick Loriot
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* 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 "CCControlColourPickerTest.h"
|
||||
|
||||
USING_NS_CC_EXT;
|
||||
|
|
|
@ -1,28 +1,3 @@
|
|||
/*
|
||||
* ControlColourPickerTest.h
|
||||
*
|
||||
* Copyright (c) 2012 Yannick Loriot
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* 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 "../CCControlScene.h"
|
||||
#include "extensions/cocos-ext.h"
|
||||
|
||||
|
@ -33,12 +8,12 @@ class ControlColourPickerTest : public ControlScene
|
|||
public:
|
||||
ControlColourPickerTest();
|
||||
virtual ~ControlColourPickerTest();
|
||||
bool init();
|
||||
virtual bool init() override;
|
||||
/** Callback for the change value. */
|
||||
void colourValueChanged(Ref *sender, Control::EventType controlEvent);
|
||||
|
||||
CC_SYNTHESIZE_RETAIN(Label*, _colorLabel, ColorLabel)
|
||||
|
||||
CONTROL_SCENE_CREATE_FUNC(ControlColourPickerTest)
|
||||
CREATE_FUNC(ControlColourPickerTest)
|
||||
};
|
||||
|
||||
|
|
|
@ -32,12 +32,12 @@ class ControlPotentiometerTest : public ControlScene
|
|||
public:
|
||||
ControlPotentiometerTest();
|
||||
virtual ~ControlPotentiometerTest();
|
||||
bool init();
|
||||
virtual bool init() override;
|
||||
CC_SYNTHESIZE_RETAIN(Label*, _displayValueLabel, DisplayValueLabel)
|
||||
|
||||
void valueChanged(Ref *sender, Control::EventType controlEvent);
|
||||
|
||||
CONTROL_SCENE_CREATE_FUNC(ControlPotentiometerTest)
|
||||
CREATE_FUNC(ControlPotentiometerTest)
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -27,27 +27,10 @@
|
|||
#include "CCControlSceneManager.h"
|
||||
#include "../ExtensionsTest.h"
|
||||
|
||||
ControlScene::ControlScene()
|
||||
: _sceneTitleLabel(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ControlScene::~ControlScene()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(_sceneTitleLabel);
|
||||
}
|
||||
|
||||
bool ControlScene::init()
|
||||
{
|
||||
if (Layer::init())
|
||||
if (TestCase::init())
|
||||
{
|
||||
auto pBackItem = MenuItemFont::create("Back", CC_CALLBACK_1(ControlScene::toExtensionsMainLayer, this));
|
||||
pBackItem->setPosition(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25);
|
||||
auto pBackMenu = Menu::create(pBackItem, nullptr);
|
||||
pBackMenu->setPosition( Vec2::ZERO );
|
||||
addChild(pBackMenu, 10);
|
||||
|
||||
// Add the generated background
|
||||
auto background = Sprite::create("extensions/background.png");
|
||||
background->setPosition(VisibleRect::center());
|
||||
|
@ -58,49 +41,8 @@ bool ControlScene::init()
|
|||
ribbon->setContentSize(Size(VisibleRect::getVisibleRect().size.width, 57));
|
||||
ribbon->setPosition(VisibleRect::center().x, VisibleRect::top().y - ribbon->getContentSize().height / 2.0f);
|
||||
addChild(ribbon);
|
||||
|
||||
// Add the title
|
||||
setSceneTitleLabel(Label::createWithTTF("Title", "fonts/arial.ttf", 12));
|
||||
_sceneTitleLabel->setPosition(VisibleRect::center().x, VisibleRect::top().y - _sceneTitleLabel->getContentSize().height / 2 - 5);
|
||||
addChild(_sceneTitleLabel, 1);
|
||||
|
||||
// Add the menu
|
||||
auto item1 = MenuItemImage::create("Images/b1.png", "Images/b2.png", CC_CALLBACK_1(ControlScene::previousCallback, this));
|
||||
auto item2 = MenuItemImage::create("Images/r1.png", "Images/r2.png", CC_CALLBACK_1(ControlScene::restartCallback, this));
|
||||
auto item3 = MenuItemImage::create("Images/f1.png", "Images/f2.png", CC_CALLBACK_1(ControlScene::nextCallback, this));
|
||||
|
||||
auto menu = Menu::create(item1, item3, item2, nullptr);
|
||||
menu->setPosition(Vec2::ZERO);
|
||||
item1->setPosition(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2);
|
||||
item2->setPosition(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2);
|
||||
item3->setPosition(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2);
|
||||
|
||||
addChild(menu ,1);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ControlScene::toExtensionsMainLayer(Ref* sender)
|
||||
{
|
||||
auto scene = new (std::nothrow) ExtensionsTestScene();
|
||||
scene->runThisTest();
|
||||
scene->release();
|
||||
}
|
||||
|
||||
void ControlScene::previousCallback(Ref* sender)
|
||||
{
|
||||
Director::getInstance()->replaceScene(ControlSceneManager::sharedControlSceneManager()->previousControlScene());
|
||||
}
|
||||
|
||||
void ControlScene::restartCallback(Ref* sender)
|
||||
{
|
||||
Director::getInstance()->replaceScene(ControlSceneManager::sharedControlSceneManager()->currentControlScene());
|
||||
}
|
||||
|
||||
void ControlScene::nextCallback(Ref* sender)
|
||||
{
|
||||
Director::getInstance()->replaceScene(ControlSceneManager::sharedControlSceneManager()->nextControlScene());
|
||||
}
|
||||
|
||||
|
|
|
@ -28,47 +28,17 @@
|
|||
|
||||
#include "cocos2d.h"
|
||||
#include "extensions/cocos-ext.h"
|
||||
|
||||
#include "BaseTest.h"
|
||||
|
||||
USING_NS_CC;
|
||||
USING_NS_CC_EXT;
|
||||
|
||||
#define CONTROL_SCENE_CREATE_FUNC(controlScene) \
|
||||
public: \
|
||||
static Scene* sceneWithTitle(const char * title) \
|
||||
{ \
|
||||
Scene* scene = Scene::create(); \
|
||||
controlScene* controlLayer = new controlScene(); \
|
||||
if (controlLayer && controlLayer->init()) \
|
||||
{ \
|
||||
controlLayer->autorelease(); \
|
||||
controlLayer->getSceneTitleLabel()->setString(title); \
|
||||
scene->addChild(controlLayer); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
CC_SAFE_DELETE(controlLayer); \
|
||||
} \
|
||||
return scene; \
|
||||
}
|
||||
|
||||
|
||||
class ControlScene : public Layer
|
||||
class ControlScene : public TestCase
|
||||
{
|
||||
public:
|
||||
ControlScene();
|
||||
~ControlScene();
|
||||
bool init();
|
||||
// Menu Callbacks
|
||||
void toExtensionsMainLayer(Ref* sender);
|
||||
void previousCallback(Ref* sender);
|
||||
void restartCallback(Ref* sender);
|
||||
void nextCallback(Ref* sender);
|
||||
virtual bool init() override;
|
||||
|
||||
/** Title label of the scene. */
|
||||
CC_SYNTHESIZE_RETAIN(Label*, _sceneTitleLabel, SceneTitleLabel)
|
||||
|
||||
CONTROL_SCENE_CREATE_FUNC(ControlScene);
|
||||
virtual std::string title() const override { return getTestCaseName(); }
|
||||
};
|
||||
|
||||
#endif /* __CCCONTROLSCENE_H__ */
|
||||
|
|
|
@ -1,28 +1,3 @@
|
|||
/*
|
||||
* ControlSceneManager.m
|
||||
*
|
||||
* Copyright (c) 2011 Yannick Loriot
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* 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 "CCControlSceneManager.h"
|
||||
#include "CCControlScene.h"
|
||||
#include "CCControlButtonTest/CCControlButtonTest.h"
|
||||
|
@ -34,82 +9,14 @@
|
|||
|
||||
USING_NS_CC;
|
||||
|
||||
enum
|
||||
ControlTests::ControlTests()
|
||||
{
|
||||
kControlSliderTest = 0,
|
||||
kControlColourPickerTest,
|
||||
kControlSwitchTest,
|
||||
kControlButtonTest_HelloVariableSize,
|
||||
kControlButtonTest_Event,
|
||||
kControlButtonTest_Styling,
|
||||
kControlPotentiometerTest,
|
||||
kControlStepperTest,
|
||||
kControlTestMax
|
||||
};
|
||||
|
||||
static const char* s_testArray[] = {
|
||||
"CCControlSliderTest",
|
||||
"ControlColourPickerTest",
|
||||
"ControlSwitchTest",
|
||||
"ControlButtonTest_HelloVariableSize",
|
||||
"ControlButtonTest_Event",
|
||||
"ControlButtonTest_Styling",
|
||||
"ControlPotentiometerTest",
|
||||
"CCControlStepperTest"
|
||||
};
|
||||
|
||||
static ControlSceneManager *sharedInstance = nullptr;
|
||||
|
||||
|
||||
ControlSceneManager::ControlSceneManager()
|
||||
{
|
||||
_currentControlSceneId = kControlSliderTest;
|
||||
}
|
||||
|
||||
ControlSceneManager::~ControlSceneManager()
|
||||
{
|
||||
CC_SAFE_RELEASE(sharedInstance);
|
||||
}
|
||||
|
||||
ControlSceneManager * ControlSceneManager::sharedControlSceneManager()
|
||||
{
|
||||
if (sharedInstance == nullptr)
|
||||
{
|
||||
sharedInstance = new (std::nothrow) ControlSceneManager();
|
||||
}
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
Scene *ControlSceneManager::nextControlScene()
|
||||
{
|
||||
_currentControlSceneId = (_currentControlSceneId + 1) % kControlTestMax;
|
||||
|
||||
return currentControlScene();
|
||||
}
|
||||
|
||||
Scene *ControlSceneManager::previousControlScene()
|
||||
{
|
||||
_currentControlSceneId = _currentControlSceneId - 1;
|
||||
if (_currentControlSceneId < 0)
|
||||
{
|
||||
_currentControlSceneId = kControlTestMax - 1;
|
||||
}
|
||||
|
||||
return currentControlScene();
|
||||
}
|
||||
|
||||
Scene *ControlSceneManager::currentControlScene()
|
||||
{
|
||||
switch (_currentControlSceneId)
|
||||
{
|
||||
case kControlSliderTest: return ControlSliderTest::sceneWithTitle(s_testArray[_currentControlSceneId]);
|
||||
case kControlColourPickerTest:return ControlColourPickerTest::sceneWithTitle(s_testArray[_currentControlSceneId]);
|
||||
case kControlSwitchTest:return ControlSwitchTest::sceneWithTitle(s_testArray[_currentControlSceneId]);
|
||||
case kControlButtonTest_HelloVariableSize:return ControlButtonTest_HelloVariableSize::sceneWithTitle(s_testArray[_currentControlSceneId]);
|
||||
case kControlButtonTest_Event:return ControlButtonTest_Event::sceneWithTitle(s_testArray[_currentControlSceneId]);
|
||||
case kControlButtonTest_Styling:return ControlButtonTest_Styling::sceneWithTitle(s_testArray[_currentControlSceneId]);
|
||||
case kControlPotentiometerTest:return ControlPotentiometerTest::sceneWithTitle(s_testArray[_currentControlSceneId]);
|
||||
case kControlStepperTest:return ControlStepperTest::sceneWithTitle(s_testArray[_currentControlSceneId]);
|
||||
}
|
||||
return nullptr;
|
||||
addTestCase("CCControlSliderTest", [](){ return ControlSliderTest::create(); });
|
||||
addTestCase("ControlColourPickerTest", [](){ return ControlColourPickerTest::create(); });
|
||||
addTestCase("ControlSwitchTest", [](){ return ControlSwitchTest::create(); });
|
||||
addTestCase("ControlButtonTest_HelloVariableSize", [](){ return ControlButtonTest_HelloVariableSize::create(); });
|
||||
addTestCase("ControlButtonTest_Event", [](){ return ControlButtonTest_Event::create(); });
|
||||
addTestCase("ControlButtonTest_Styling", [](){ return ControlButtonTest_Styling::create(); });
|
||||
addTestCase("ControlPotentiometerTest", [](){ return ControlPotentiometerTest::create(); });
|
||||
addTestCase("CCControlStepperTest", [](){ return ControlStepperTest::create(); });
|
||||
}
|
||||
|
|
|
@ -27,28 +27,10 @@
|
|||
|
||||
#include "cocos2d.h"
|
||||
#include "extensions/cocos-ext.h"
|
||||
#include "BaseTest.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
class ControlSceneManager : public cocos2d::Ref
|
||||
{
|
||||
public:
|
||||
ControlSceneManager();
|
||||
~ControlSceneManager();
|
||||
/** Returns the singleton of the control scene manager. */
|
||||
static ControlSceneManager * sharedControlSceneManager();
|
||||
|
||||
/** Returns the next control scene. */
|
||||
cocos2d::Scene *nextControlScene();
|
||||
|
||||
/** Returns the previous control scene. */
|
||||
cocos2d::Scene *previousControlScene();
|
||||
|
||||
/** Returns the current control scene. */
|
||||
cocos2d::Scene *currentControlScene();
|
||||
|
||||
/** Control scene id. */
|
||||
CC_SYNTHESIZE(int, _currentControlSceneId, CurrentControlSceneId)
|
||||
};
|
||||
DEFINE_TEST_SUITE(ControlTests);
|
||||
|
||||
#endif /* __CCCONTROLSCENEMANAGER_H__ */
|
||||
|
|
|
@ -33,7 +33,6 @@ ControlSliderTest::ControlSliderTest()
|
|||
|
||||
ControlSliderTest::~ControlSliderTest()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(_displayValueLabel);
|
||||
}
|
||||
|
||||
bool ControlSliderTest::init()
|
||||
|
@ -43,10 +42,8 @@ bool ControlSliderTest::init()
|
|||
auto screenSize = Director::getInstance()->getWinSize();
|
||||
|
||||
// Add a label in which the slider value will be displayed
|
||||
_displayValueLabel = Label::createWithTTF("Move the slider thumb!\nThe lower slider is restricted." ,"fonts/Marker Felt.ttf", 32);
|
||||
_displayValueLabel->retain();
|
||||
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
||||
_displayValueLabel->setPosition(screenSize.width / 1.7f, screenSize.height / 2.0f);
|
||||
_displayValueLabel = Label::createWithTTF("Move the slider thumb!\nThe lower slider is restricted." ,"fonts/Marker Felt.ttf", 20);
|
||||
_displayValueLabel->setPosition(screenSize.width / 2.0f, screenSize.height * 0.7f);
|
||||
addChild(_displayValueLabel);
|
||||
|
||||
// Add the slider
|
||||
|
|
|
@ -28,12 +28,14 @@
|
|||
class ControlSliderTest : public ControlScene
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(ControlSliderTest);
|
||||
|
||||
ControlSliderTest();
|
||||
virtual ~ControlSliderTest();
|
||||
bool init();
|
||||
virtual bool init() override;
|
||||
void valueChanged(Ref *sender, Control::EventType controlEvent);
|
||||
protected:
|
||||
Label* _displayValueLabel;
|
||||
CONTROL_SCENE_CREATE_FUNC(ControlSliderTest)
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -31,9 +31,10 @@
|
|||
class ControlStepperTest : public ControlScene
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(ControlStepperTest);
|
||||
ControlStepperTest();
|
||||
virtual ~ControlStepperTest();
|
||||
bool init();
|
||||
virtual bool init() override;
|
||||
/** Creates and returns a new ControlStepper. */
|
||||
ControlStepper* makeControlStepper();
|
||||
|
||||
|
@ -41,7 +42,7 @@ public:
|
|||
void valueChanged(Ref *sender, Control::EventType controlEvent);
|
||||
protected:
|
||||
CC_SYNTHESIZE_RETAIN(Label*, _displayValueLabel, DisplayValueLabel)
|
||||
CONTROL_SCENE_CREATE_FUNC(ControlStepperTest)
|
||||
|
||||
};
|
||||
|
||||
#endif /* __CCCONTROLSTEPPERTEST_H__ */
|
||||
|
|
|
@ -30,10 +30,10 @@ class ControlSwitchTest : public ControlScene
|
|||
{
|
||||
public:
|
||||
virtual ~ControlSwitchTest();
|
||||
bool init();
|
||||
virtual bool init() override;
|
||||
/** Callback for the change value. */
|
||||
void valueChanged(Ref* sender, Control::EventType controlEvent);
|
||||
Label *_displayValueLabel;
|
||||
CONTROL_SCENE_CREATE_FUNC(ControlSwitchTest)
|
||||
CREATE_FUNC(ControlSwitchTest);
|
||||
};
|
||||
|
||||
|
|
|
@ -19,180 +19,22 @@
|
|||
#include "NetworkTest/SocketIOTest.h"
|
||||
#endif
|
||||
|
||||
|
||||
enum
|
||||
ExtensionsTests::ExtensionsTests()
|
||||
{
|
||||
LINE_SPACE = 40,
|
||||
kItemTagBasic = 1000,
|
||||
};
|
||||
|
||||
static struct {
|
||||
const char *name;
|
||||
std::function<void(Ref* sender)> callback;
|
||||
} g_extensionsTests[] = {
|
||||
{ "AssetsManagerExTest", [](Ref* sender) {
|
||||
AssetsManagerExLoaderScene *scene = new AssetsManagerExLoaderScene();
|
||||
scene->runThisTest();
|
||||
} },
|
||||
{ "NotificationCenterTest", [](Ref* sender) { runNotificationCenterTest(); }
|
||||
},
|
||||
{ "CCControlButtonTest", [](Ref *sender){
|
||||
ControlSceneManager* pManager = ControlSceneManager::sharedControlSceneManager();
|
||||
auto scene = pManager->currentControlScene();
|
||||
Director::getInstance()->replaceScene(scene);
|
||||
}},
|
||||
{ "CocosBuilderTest", [](Ref *sender) {
|
||||
auto scene = new (std::nothrow) CocosBuilderTestScene();
|
||||
if (scene)
|
||||
{
|
||||
scene->runThisTest();
|
||||
scene->release();
|
||||
}
|
||||
}},
|
||||
addTest("AssetsManagerExTest", [](){ return new (std::nothrow) AssetsManagerExTests; });
|
||||
addTest("NotificationCenterTest", [](){ return new (std::nothrow) NotificationCenterTests; });
|
||||
addTest("CCControlButtonTest", [](){ return new (std::nothrow) ControlTests; });
|
||||
addTest("CocosBuilderTest", [](){ return new (std::nothrow) CocosBuilderTests; });
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_EMSCRIPTEN) && (CC_TARGET_PLATFORM != CC_PLATFORM_NACL)
|
||||
{ "HttpClientTest", [](Ref *sender){ runHttpClientTest();}
|
||||
},
|
||||
addTest("HttpClientTest", [](){ return new (std::nothrow) HttpClientTests; });
|
||||
#endif
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
||||
{ "WebSocketTest", [](Ref *sender){ runWebSocketTest();}
|
||||
},
|
||||
{ "SocketIOTest", [](Ref *sender){ runSocketIOTest();}
|
||||
},
|
||||
addTest("WebSocketTest", [](){ return new (std::nothrow) WebSocketTests; });
|
||||
addTest("SocketIOTest", [](){ return new (std::nothrow) SocketIOTests; });
|
||||
#endif
|
||||
|
||||
{ "TableViewTest", [](Ref *sender){ runTableViewTest();}
|
||||
},
|
||||
{ "CocoStudioArmatureTest", [](Ref *sender) { ArmatureTestScene *scene = new (std::nothrow) ArmatureTestScene();
|
||||
scene->runThisTest();
|
||||
scene->release();
|
||||
}
|
||||
},
|
||||
{ "CocoStudioActionTimelineTest", [](Ref *sender) { ActionTimelineTestScene *scene = new (std::nothrow) ActionTimelineTestScene();
|
||||
scene->runThisTest();
|
||||
scene->release();
|
||||
}
|
||||
},
|
||||
{ "CocoStudioComponentsTest", [](Ref *sender) { runComponentsTestLayerTest(); }
|
||||
},
|
||||
{ "CocoStudioSceneTest", [](Ref *sender) { SceneEditorTestScene *scene = new (std::nothrow) SceneEditorTestScene();
|
||||
scene->runThisTest();
|
||||
scene->release();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
static const int g_maxTests = sizeof(g_extensionsTests) / sizeof(g_extensionsTests[0]);
|
||||
|
||||
static Vec2 s_tCurPos = Vec2::ZERO;
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// ExtensionsMainLayer
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
void ExtensionsMainLayer::onEnter()
|
||||
{
|
||||
Layer::onEnter();
|
||||
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
|
||||
_itemMenu = Menu::create();
|
||||
_itemMenu->setPosition( Vec2::ZERO );
|
||||
MenuItemFont::setFontName("fonts/arial.ttf");
|
||||
MenuItemFont::setFontSize(24);
|
||||
for (int i = 0; i < g_maxTests; ++i)
|
||||
{
|
||||
auto pItem = MenuItemFont::create(g_extensionsTests[i].name, g_extensionsTests[i].callback);
|
||||
pItem->setPosition(Vec2(s.width / 2, s.height - (i + 1) * LINE_SPACE));
|
||||
_itemMenu->addChild(pItem, kItemTagBasic + i);
|
||||
}
|
||||
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesBegan = CC_CALLBACK_2(ExtensionsMainLayer::onTouchesBegan, this);
|
||||
listener->onTouchesMoved = CC_CALLBACK_2(ExtensionsMainLayer::onTouchesMoved, this);
|
||||
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||
|
||||
auto mouseListener = EventListenerMouse::create();
|
||||
mouseListener->onMouseScroll = CC_CALLBACK_1(ExtensionsMainLayer::onMouseScroll, this);
|
||||
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(mouseListener, this);
|
||||
|
||||
addChild(_itemMenu);
|
||||
addTest("TableViewTest", [](){ return new (std::nothrow) TableViewTests; });
|
||||
addTest("CocoStudioArmatureTest", [](){ return new (std::nothrow) CocoStudioArmatureTests; });
|
||||
addTest("CocoStudioActionTimelineTest", [](){ return new (std::nothrow) CocoStudioActionTimelineTests; });
|
||||
addTest("CocoStudioComponentsTest", [](){ return new (std::nothrow) CocoStudioComponentsTests; });
|
||||
addTest("CocoStudioSceneTest", [](){ return new (std::nothrow) CocoStudioSceneEditTests; });
|
||||
}
|
||||
|
||||
|
||||
void ExtensionsMainLayer::onTouchesBegan(const std::vector<Touch*>& touches, Event *event)
|
||||
{
|
||||
auto touch = static_cast<Touch*>(touches[0]);
|
||||
|
||||
_beginPos = touch->getLocation();
|
||||
}
|
||||
|
||||
void ExtensionsMainLayer::onTouchesMoved(const std::vector<Touch*>& touches, Event *event)
|
||||
{
|
||||
auto touch = static_cast<Touch*>(touches[0]);
|
||||
|
||||
auto touchLocation = touch->getLocation();
|
||||
float nMoveY = touchLocation.y - _beginPos.y;
|
||||
|
||||
auto curPos = _itemMenu->getPosition();
|
||||
auto nextPos = Vec2(curPos.x, curPos.y + nMoveY);
|
||||
|
||||
if (nextPos.y < 0.0f)
|
||||
{
|
||||
_itemMenu->setPosition(Vec2::ZERO);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextPos.y > ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))
|
||||
{
|
||||
_itemMenu->setPosition(0, ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height));
|
||||
return;
|
||||
}
|
||||
|
||||
_itemMenu->setPosition(nextPos);
|
||||
_beginPos = touchLocation;
|
||||
s_tCurPos = nextPos;
|
||||
}
|
||||
|
||||
void ExtensionsMainLayer::onMouseScroll(Event* event)
|
||||
{
|
||||
auto mouseEvent = static_cast<EventMouse*>(event);
|
||||
float nMoveY = mouseEvent->getScrollY() * 6;
|
||||
|
||||
auto curPos = _itemMenu->getPosition();
|
||||
auto nextPos = Vec2(curPos.x, curPos.y + nMoveY);
|
||||
|
||||
if (nextPos.y < 0.0f)
|
||||
{
|
||||
_itemMenu->setPosition(Vec2::ZERO);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextPos.y > ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))
|
||||
{
|
||||
_itemMenu->setPosition(0, ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height));
|
||||
return;
|
||||
}
|
||||
|
||||
_itemMenu->setPosition(nextPos);
|
||||
s_tCurPos = nextPos;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// ExtensionsTestScene
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
void ExtensionsTestScene::runThisTest()
|
||||
{
|
||||
auto layer = new (std::nothrow) ExtensionsMainLayer();
|
||||
addChild(layer);
|
||||
layer->release();
|
||||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,29 +1,8 @@
|
|||
#ifndef __EXTENSIONS_TEST_H__
|
||||
#define __EXTENSIONS_TEST_H__
|
||||
|
||||
#include "../testBasic.h"
|
||||
#include "BaseTest.h"
|
||||
|
||||
class ExtensionsMainLayer : public Layer
|
||||
{
|
||||
public:
|
||||
virtual void onEnter() override;
|
||||
|
||||
void onTouchesBegan(const std::vector<Touch*>& touches, Event *event) override;
|
||||
void onTouchesMoved(const std::vector<Touch*>& touches, Event *event) override;
|
||||
|
||||
Vec2 _beginPos;
|
||||
Menu* _itemMenu;
|
||||
|
||||
int _testcount;
|
||||
|
||||
protected:
|
||||
void onMouseScroll(Event* event);
|
||||
};
|
||||
|
||||
class ExtensionsTestScene : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
DEFINE_TEST_LIST(ExtensionsTests);
|
||||
|
||||
#endif /* __EXTENSIONS_TEST_H__ */
|
||||
|
|
|
@ -6,6 +6,11 @@ USING_NS_CC;
|
|||
USING_NS_CC_EXT;
|
||||
using namespace cocos2d::network;
|
||||
|
||||
HttpClientTests::HttpClientTests()
|
||||
{
|
||||
ADD_TEST_CASE(HttpClientTest);
|
||||
}
|
||||
|
||||
HttpClientTest::HttpClientTest()
|
||||
: _labelStatusCode(nullptr)
|
||||
{
|
||||
|
@ -17,10 +22,6 @@ HttpClientTest::HttpClientTest()
|
|||
const int LEFT = winSize.width / 4;
|
||||
const int RIGHT = winSize.width / 4 * 3;
|
||||
|
||||
auto label = Label::createWithTTF("Http Request Test", "fonts/arial.ttf", 28);
|
||||
label->setPosition(winSize.width / 2, winSize.height - MARGIN);
|
||||
addChild(label, 0);
|
||||
|
||||
auto menuRequest = Menu::create();
|
||||
menuRequest->setPosition(Vec2::ZERO);
|
||||
addChild(menuRequest);
|
||||
|
@ -89,13 +90,6 @@ HttpClientTest::HttpClientTest()
|
|||
_labelStatusCode = Label::createWithTTF("HTTP Status Code", "fonts/arial.ttf", 18);
|
||||
_labelStatusCode->setPosition(winSize.width / 2, winSize.height - MARGIN - 6 * SPACE);
|
||||
addChild(_labelStatusCode);
|
||||
|
||||
// Back Menu
|
||||
auto itemBack = MenuItemFont::create("Back", CC_CALLBACK_1(HttpClientTest::toExtensionsMainLayer, this));
|
||||
itemBack->setPosition(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25);
|
||||
auto menuBack = Menu::create(itemBack, nullptr);
|
||||
menuBack->setPosition(Vec2::ZERO);
|
||||
addChild(menuBack);
|
||||
}
|
||||
|
||||
HttpClientTest::~HttpClientTest()
|
||||
|
@ -380,20 +374,3 @@ void HttpClientTest::onHttpRequestCompleted(HttpClient *sender, HttpResponse *re
|
|||
log("request ref count not 2, is %d", response->getHttpRequest()->getReferenceCount());
|
||||
}
|
||||
}
|
||||
|
||||
void HttpClientTest::toExtensionsMainLayer(cocos2d::Ref *sender)
|
||||
{
|
||||
auto scene = new (std::nothrow) ExtensionsTestScene();
|
||||
scene->runThisTest();
|
||||
scene->release();
|
||||
}
|
||||
|
||||
void runHttpClientTest()
|
||||
{
|
||||
auto scene = Scene::create();
|
||||
HttpClientTest *layer = new (std::nothrow) HttpClientTest();
|
||||
scene->addChild(layer);
|
||||
|
||||
Director::getInstance()->replaceScene(scene);
|
||||
layer->release();
|
||||
}
|
||||
|
|
|
@ -4,13 +4,17 @@
|
|||
#include "cocos2d.h"
|
||||
#include "extensions/cocos-ext.h"
|
||||
#include "network/HttpClient.h"
|
||||
#include "BaseTest.h"
|
||||
|
||||
class HttpClientTest : public cocos2d::Layer
|
||||
DEFINE_TEST_SUITE(HttpClientTests);
|
||||
|
||||
class HttpClientTest : public TestCase
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(HttpClientTest);
|
||||
|
||||
HttpClientTest();
|
||||
virtual ~HttpClientTest();
|
||||
void toExtensionsMainLayer(cocos2d::Ref *sender);
|
||||
|
||||
//Menu Callbacks
|
||||
void onMenuGetTestClicked(cocos2d::Ref *sender, bool isImmediate);
|
||||
|
@ -22,10 +26,10 @@ public:
|
|||
//Http Response Callback
|
||||
void onHttpRequestCompleted(cocos2d::network::HttpClient *sender, cocos2d::network::HttpResponse *response);
|
||||
|
||||
virtual std::string title() const override { return "Http Request Test"; }
|
||||
|
||||
private:
|
||||
cocos2d::Label* _labelStatusCode;
|
||||
};
|
||||
|
||||
void runHttpClientTest();
|
||||
|
||||
#endif //__HTTPREQUESTHTTP_H
|
||||
|
|
|
@ -14,7 +14,12 @@ USING_NS_CC;
|
|||
USING_NS_CC_EXT;
|
||||
using namespace cocos2d::network;
|
||||
|
||||
SocketIOTestLayer::SocketIOTestLayer(void)
|
||||
SocketIOTests::SocketIOTests()
|
||||
{
|
||||
ADD_TEST_CASE(SocketIOTest);
|
||||
}
|
||||
|
||||
SocketIOTest::SocketIOTest()
|
||||
: _sioClient(nullptr)
|
||||
, _sioEndpoint(nullptr)
|
||||
{
|
||||
|
@ -24,10 +29,6 @@ SocketIOTestLayer::SocketIOTestLayer(void)
|
|||
|
||||
const int MARGIN = 40;
|
||||
const int SPACE = 35;
|
||||
|
||||
auto label = Label::createWithTTF("SocketIO Extension Test", "fonts/arial.ttf", 28);
|
||||
label->setPosition(Vec2(winSize.width / 2, winSize.height - MARGIN));
|
||||
addChild(label, 0);
|
||||
|
||||
auto menuRequest = Menu::create();
|
||||
menuRequest->setPosition(Vec2::ZERO);
|
||||
|
@ -35,49 +36,49 @@ SocketIOTestLayer::SocketIOTestLayer(void)
|
|||
|
||||
// Test to create basic client in the default namespace
|
||||
auto labelSIOClient = Label::createWithTTF("Open SocketIO Client", "fonts/arial.ttf", 22);
|
||||
auto itemSIOClient = MenuItemLabel::create(labelSIOClient, CC_CALLBACK_1(SocketIOTestLayer::onMenuSIOClientClicked, this));
|
||||
auto itemSIOClient = MenuItemLabel::create(labelSIOClient, CC_CALLBACK_1(SocketIOTest::onMenuSIOClientClicked, this));
|
||||
itemSIOClient->setPosition(Vec2(VisibleRect::left().x + labelSIOClient->getContentSize().width / 2 + 5, winSize.height - MARGIN - SPACE));
|
||||
menuRequest->addChild(itemSIOClient);
|
||||
|
||||
// Test to create a client at the endpoint '/testpoint'
|
||||
auto labelSIOEndpoint = Label::createWithTTF("Open SocketIO Endpoint", "fonts/arial.ttf", 22);
|
||||
auto itemSIOEndpoint = MenuItemLabel::create(labelSIOEndpoint, CC_CALLBACK_1(SocketIOTestLayer::onMenuSIOEndpointClicked, this));
|
||||
auto itemSIOEndpoint = MenuItemLabel::create(labelSIOEndpoint, CC_CALLBACK_1(SocketIOTest::onMenuSIOEndpointClicked, this));
|
||||
itemSIOEndpoint->setPosition(Vec2(VisibleRect::right().x - labelSIOEndpoint->getContentSize().width / 2 - 5, winSize.height - MARGIN - SPACE));
|
||||
menuRequest->addChild(itemSIOEndpoint);
|
||||
|
||||
// Test sending message to default namespace
|
||||
auto labelTestMessage = Label::createWithTTF("Send Test Message", "fonts/arial.ttf", 22);
|
||||
auto itemTestMessage = MenuItemLabel::create(labelTestMessage, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestMessageClicked, this));
|
||||
auto itemTestMessage = MenuItemLabel::create(labelTestMessage, CC_CALLBACK_1(SocketIOTest::onMenuTestMessageClicked, this));
|
||||
itemTestMessage->setPosition(Vec2(VisibleRect::left().x + labelTestMessage->getContentSize().width / 2 + 5, winSize.height - MARGIN - 2 * SPACE));
|
||||
menuRequest->addChild(itemTestMessage);
|
||||
|
||||
// Test sending message to the endpoint '/testpoint'
|
||||
auto labelTestMessageEndpoint = Label::createWithTTF("Test Endpoint Message", "fonts/arial.ttf", 22);
|
||||
auto itemTestMessageEndpoint = MenuItemLabel::create(labelTestMessageEndpoint, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestMessageEndpointClicked, this));
|
||||
auto itemTestMessageEndpoint = MenuItemLabel::create(labelTestMessageEndpoint, CC_CALLBACK_1(SocketIOTest::onMenuTestMessageEndpointClicked, this));
|
||||
itemTestMessageEndpoint->setPosition(Vec2(VisibleRect::right().x - labelTestMessageEndpoint->getContentSize().width / 2 - 5, winSize.height - MARGIN - 2 * SPACE));
|
||||
menuRequest->addChild(itemTestMessageEndpoint);
|
||||
|
||||
// Test sending event 'echotest' to default namespace
|
||||
auto labelTestEvent = Label::createWithTTF("Send Test Event", "fonts/arial.ttf", 22);
|
||||
auto itemTestEvent = MenuItemLabel::create(labelTestEvent, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestEventClicked, this));
|
||||
auto itemTestEvent = MenuItemLabel::create(labelTestEvent, CC_CALLBACK_1(SocketIOTest::onMenuTestEventClicked, this));
|
||||
itemTestEvent->setPosition(Vec2(VisibleRect::left().x + labelTestEvent->getContentSize().width / 2 + 5, winSize.height - MARGIN - 3 * SPACE));
|
||||
menuRequest->addChild(itemTestEvent);
|
||||
|
||||
// Test sending event 'echotest' to the endpoint '/testpoint'
|
||||
auto labelTestEventEndpoint = Label::createWithTTF("Test Endpoint Event", "fonts/arial.ttf", 22);
|
||||
auto itemTestEventEndpoint = MenuItemLabel::create(labelTestEventEndpoint, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestEventEndpointClicked, this));
|
||||
auto itemTestEventEndpoint = MenuItemLabel::create(labelTestEventEndpoint, CC_CALLBACK_1(SocketIOTest::onMenuTestEventEndpointClicked, this));
|
||||
itemTestEventEndpoint->setPosition(Vec2(VisibleRect::right().x - labelTestEventEndpoint->getContentSize().width / 2 - 5, winSize.height - MARGIN - 3 * SPACE));
|
||||
menuRequest->addChild(itemTestEventEndpoint);
|
||||
|
||||
// Test disconnecting basic client
|
||||
auto labelTestClientDisconnect = Label::createWithTTF("Disconnect Socket", "fonts/arial.ttf", 22);
|
||||
auto itemClientDisconnect = MenuItemLabel::create(labelTestClientDisconnect, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestClientDisconnectClicked, this));
|
||||
auto itemClientDisconnect = MenuItemLabel::create(labelTestClientDisconnect, CC_CALLBACK_1(SocketIOTest::onMenuTestClientDisconnectClicked, this));
|
||||
itemClientDisconnect->setPosition(Vec2(VisibleRect::left().x + labelTestClientDisconnect->getContentSize().width / 2 + 5, winSize.height - MARGIN - 4 * SPACE));
|
||||
menuRequest->addChild(itemClientDisconnect);
|
||||
|
||||
// Test disconnecting the endpoint '/testpoint'
|
||||
auto labelTestEndpointDisconnect = Label::createWithTTF("Disconnect Endpoint", "fonts/arial.ttf", 22);
|
||||
auto itemTestEndpointDisconnect = MenuItemLabel::create(labelTestEndpointDisconnect, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestEndpointDisconnectClicked, this));
|
||||
auto itemTestEndpointDisconnect = MenuItemLabel::create(labelTestEndpointDisconnect, CC_CALLBACK_1(SocketIOTest::onMenuTestEndpointDisconnectClicked, this));
|
||||
itemTestEndpointDisconnect->setPosition(Vec2(VisibleRect::right().x - labelTestEndpointDisconnect->getContentSize().width / 2 - 5, winSize.height - MARGIN - 4 * SPACE));
|
||||
menuRequest->addChild(itemTestEndpointDisconnect);
|
||||
|
||||
|
@ -86,25 +87,16 @@ SocketIOTestLayer::SocketIOTestLayer(void)
|
|||
_sioClientStatus->setAnchorPoint(Vec2(0, 0));
|
||||
_sioClientStatus->setPosition(Vec2(VisibleRect::left().x, VisibleRect::rightBottom().y));
|
||||
this->addChild(_sioClientStatus);
|
||||
|
||||
// Back Menu
|
||||
auto itemBack = MenuItemFont::create("Back", CC_CALLBACK_1(SocketIOTestLayer::toExtensionsMainLayer, this));
|
||||
itemBack->setPosition(Vec2(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
|
||||
auto menuBack = Menu::create(itemBack, nullptr);
|
||||
menuBack->setPosition(Vec2::ZERO);
|
||||
addChild(menuBack);
|
||||
|
||||
}
|
||||
|
||||
|
||||
SocketIOTestLayer::~SocketIOTestLayer(void)
|
||||
SocketIOTest::~SocketIOTest()
|
||||
{
|
||||
}
|
||||
|
||||
//test event callback handlers, these will be registered with socket.io
|
||||
void SocketIOTestLayer::testevent(SIOClient *client, const std::string& data) {
|
||||
void SocketIOTest::testevent(SIOClient *client, const std::string& data) {
|
||||
|
||||
log("SocketIOTestLayer::testevent called with data: %s", data.c_str());
|
||||
log("SocketIOTest::testevent called with data: %s", data.c_str());
|
||||
|
||||
std::stringstream s;
|
||||
s << client->getTag() << " received event testevent with data: " << data.c_str();
|
||||
|
@ -113,9 +105,9 @@ void SocketIOTestLayer::testevent(SIOClient *client, const std::string& data) {
|
|||
|
||||
}
|
||||
|
||||
void SocketIOTestLayer::echotest(SIOClient *client, const std::string& data) {
|
||||
void SocketIOTest::echotest(SIOClient *client, const std::string& data) {
|
||||
|
||||
log("SocketIOTestLayer::echotest called with data: %s", data.c_str());
|
||||
log("SocketIOTest::echotest called with data: %s", data.c_str());
|
||||
|
||||
std::stringstream s;
|
||||
s << client->getTag() << " received event echotest with data: " << data.c_str();
|
||||
|
@ -124,18 +116,7 @@ void SocketIOTestLayer::echotest(SIOClient *client, const std::string& data) {
|
|||
|
||||
}
|
||||
|
||||
void SocketIOTestLayer::toExtensionsMainLayer(cocos2d::Ref *sender)
|
||||
{
|
||||
ExtensionsTestScene *scene = new (std::nothrow) ExtensionsTestScene();
|
||||
scene->runThisTest();
|
||||
scene->release();
|
||||
|
||||
if(_sioEndpoint) _sioEndpoint->disconnect();
|
||||
if(_sioClient) _sioClient->disconnect();
|
||||
|
||||
}
|
||||
|
||||
void SocketIOTestLayer::onMenuSIOClientClicked(cocos2d::Ref *sender)
|
||||
void SocketIOTest::onMenuSIOClientClicked(cocos2d::Ref *sender)
|
||||
{
|
||||
//create a client by using this static method, url does not need to contain the protocol
|
||||
_sioClient = SocketIO::connect("ws://channon.us:3000", *this);
|
||||
|
@ -143,12 +124,12 @@ void SocketIOTestLayer::onMenuSIOClientClicked(cocos2d::Ref *sender)
|
|||
_sioClient->setTag("Test Client");
|
||||
|
||||
//register event callbacks using the CC_CALLBACK_2() macro and passing the instance of the target class
|
||||
_sioClient->on("testevent", CC_CALLBACK_2(SocketIOTestLayer::testevent, this));
|
||||
_sioClient->on("echotest", CC_CALLBACK_2(SocketIOTestLayer::echotest, this));
|
||||
_sioClient->on("testevent", CC_CALLBACK_2(SocketIOTest::testevent, this));
|
||||
_sioClient->on("echotest", CC_CALLBACK_2(SocketIOTest::echotest, this));
|
||||
|
||||
}
|
||||
|
||||
void SocketIOTestLayer::onMenuSIOEndpointClicked(cocos2d::Ref *sender)
|
||||
void SocketIOTest::onMenuSIOEndpointClicked(cocos2d::Ref *sender)
|
||||
{
|
||||
//repeat the same connection steps for the namespace "testpoint"
|
||||
_sioEndpoint = SocketIO::connect("ws://channon.us:3000/testpoint", *this);
|
||||
|
@ -156,12 +137,12 @@ void SocketIOTestLayer::onMenuSIOEndpointClicked(cocos2d::Ref *sender)
|
|||
_sioEndpoint->setTag("Test Endpoint");
|
||||
|
||||
//demonstrating how callbacks can be shared within a delegate
|
||||
_sioEndpoint->on("testevent", CC_CALLBACK_2(SocketIOTestLayer::testevent, this));
|
||||
_sioEndpoint->on("echotest", CC_CALLBACK_2(SocketIOTestLayer::echotest, this));
|
||||
_sioEndpoint->on("testevent", CC_CALLBACK_2(SocketIOTest::testevent, this));
|
||||
_sioEndpoint->on("echotest", CC_CALLBACK_2(SocketIOTest::echotest, this));
|
||||
|
||||
}
|
||||
|
||||
void SocketIOTestLayer::onMenuTestMessageClicked(cocos2d::Ref *sender)
|
||||
void SocketIOTest::onMenuTestMessageClicked(cocos2d::Ref *sender)
|
||||
{
|
||||
//check that the socket is != nullptr before sending or emitting events
|
||||
//the client should be nullptr either before initialization and connection or after disconnect
|
||||
|
@ -169,14 +150,14 @@ void SocketIOTestLayer::onMenuTestMessageClicked(cocos2d::Ref *sender)
|
|||
|
||||
}
|
||||
|
||||
void SocketIOTestLayer::onMenuTestMessageEndpointClicked(cocos2d::Ref *sender)
|
||||
void SocketIOTest::onMenuTestMessageEndpointClicked(cocos2d::Ref *sender)
|
||||
{
|
||||
|
||||
if(_sioEndpoint != nullptr) _sioEndpoint->send("Hello Socket.IO!");
|
||||
|
||||
}
|
||||
|
||||
void SocketIOTestLayer::onMenuTestEventClicked(cocos2d::Ref *sender)
|
||||
void SocketIOTest::onMenuTestEventClicked(cocos2d::Ref *sender)
|
||||
{
|
||||
//check that the socket is != nullptr before sending or emitting events
|
||||
//the client should be nullptr either before initialization and connection or after disconnect
|
||||
|
@ -184,21 +165,21 @@ void SocketIOTestLayer::onMenuTestEventClicked(cocos2d::Ref *sender)
|
|||
|
||||
}
|
||||
|
||||
void SocketIOTestLayer::onMenuTestEventEndpointClicked(cocos2d::Ref *sender)
|
||||
void SocketIOTest::onMenuTestEventEndpointClicked(cocos2d::Ref *sender)
|
||||
{
|
||||
|
||||
if(_sioEndpoint != nullptr) _sioEndpoint->emit("echotest","[{\"name\":\"myname\",\"type\":\"mytype\"}]");
|
||||
|
||||
}
|
||||
|
||||
void SocketIOTestLayer::onMenuTestClientDisconnectClicked(cocos2d::Ref *sender)
|
||||
void SocketIOTest::onMenuTestClientDisconnectClicked(cocos2d::Ref *sender)
|
||||
{
|
||||
|
||||
if(_sioClient != nullptr) _sioClient->disconnect();
|
||||
|
||||
}
|
||||
|
||||
void SocketIOTestLayer::onMenuTestEndpointDisconnectClicked(cocos2d::Ref *sender)
|
||||
void SocketIOTest::onMenuTestEndpointDisconnectClicked(cocos2d::Ref *sender)
|
||||
{
|
||||
|
||||
if(_sioEndpoint != nullptr) _sioEndpoint->disconnect();
|
||||
|
@ -207,9 +188,9 @@ void SocketIOTestLayer::onMenuTestEndpointDisconnectClicked(cocos2d::Ref *sender
|
|||
|
||||
// Delegate methods
|
||||
|
||||
void SocketIOTestLayer::onConnect(network::SIOClient* client)
|
||||
void SocketIOTest::onConnect(network::SIOClient* client)
|
||||
{
|
||||
log("SocketIOTestLayer::onConnect called");
|
||||
log("SocketIOTest::onConnect called");
|
||||
|
||||
std::stringstream s;
|
||||
s << client->getTag() << " connected!";
|
||||
|
@ -217,9 +198,9 @@ void SocketIOTestLayer::onConnect(network::SIOClient* client)
|
|||
|
||||
}
|
||||
|
||||
void SocketIOTestLayer::onMessage(network::SIOClient* client, const std::string& data)
|
||||
void SocketIOTest::onMessage(network::SIOClient* client, const std::string& data)
|
||||
{
|
||||
log("SocketIOTestLayer::onMessage received: %s", data.c_str());
|
||||
log("SocketIOTest::onMessage received: %s", data.c_str());
|
||||
|
||||
std::stringstream s;
|
||||
s << client->getTag() << " received message with content: " << data.c_str();
|
||||
|
@ -227,9 +208,9 @@ void SocketIOTestLayer::onMessage(network::SIOClient* client, const std::string&
|
|||
|
||||
}
|
||||
|
||||
void SocketIOTestLayer::onClose(network::SIOClient* client)
|
||||
void SocketIOTest::onClose(network::SIOClient* client)
|
||||
{
|
||||
log("SocketIOTestLayer::onClose called");
|
||||
log("SocketIOTest::onClose called");
|
||||
|
||||
std::stringstream s;
|
||||
s << client->getTag() << " closed!";
|
||||
|
@ -247,23 +228,11 @@ void SocketIOTestLayer::onClose(network::SIOClient* client)
|
|||
|
||||
}
|
||||
|
||||
void SocketIOTestLayer::onError(network::SIOClient* client, const std::string& data)
|
||||
void SocketIOTest::onError(network::SIOClient* client, const std::string& data)
|
||||
{
|
||||
log("SocketIOTestLayer::onError received: %s", data.c_str());
|
||||
log("SocketIOTest::onError received: %s", data.c_str());
|
||||
|
||||
std::stringstream s;
|
||||
s << client->getTag() << " received error with content: " << data.c_str();
|
||||
_sioClientStatus->setString(s.str().c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void runSocketIOTest()
|
||||
{
|
||||
auto scene = Scene::create();
|
||||
auto layer = new (std::nothrow) SocketIOTestLayer();
|
||||
scene->addChild(layer);
|
||||
|
||||
Director::getInstance()->replaceScene(scene);
|
||||
layer->release();
|
||||
}
|
||||
|
|
|
@ -11,21 +11,23 @@
|
|||
#include "cocos2d.h"
|
||||
#include "extensions/cocos-ext.h"
|
||||
#include "network/SocketIO.h"
|
||||
#include "BaseTest.h"
|
||||
|
||||
class SocketIOTestLayer
|
||||
: public cocos2d::Layer
|
||||
DEFINE_TEST_SUITE(SocketIOTests);
|
||||
|
||||
class SocketIOTest: public TestCase
|
||||
, public cocos2d::network::SocketIO::SIODelegate
|
||||
{
|
||||
public:
|
||||
SocketIOTestLayer(void);
|
||||
virtual ~SocketIOTestLayer(void);
|
||||
CREATE_FUNC(SocketIOTest);
|
||||
|
||||
SocketIOTest();
|
||||
virtual ~SocketIOTest();
|
||||
|
||||
virtual void onConnect(cocos2d::network::SIOClient* client);
|
||||
virtual void onMessage(cocos2d::network::SIOClient* client, const std::string& data);
|
||||
virtual void onClose(cocos2d::network::SIOClient* client);
|
||||
virtual void onError(cocos2d::network::SIOClient* client, const std::string& data);
|
||||
|
||||
void toExtensionsMainLayer(cocos2d::Ref *sender);
|
||||
|
||||
void onMenuSIOClientClicked(cocos2d::Ref *sender);
|
||||
void onMenuTestMessageClicked(cocos2d::Ref *sender);
|
||||
|
@ -41,11 +43,11 @@ public:
|
|||
void testevent(cocos2d::network::SIOClient *client, const std::string& data);
|
||||
void echotest(cocos2d::network::SIOClient *client, const std::string& data);
|
||||
|
||||
virtual std::string title() const override{ return "SocketIO Extension Test"; }
|
||||
|
||||
cocos2d::network::SIOClient *_sioClient, *_sioEndpoint;
|
||||
|
||||
cocos2d::Label *_sioClientStatus;
|
||||
};
|
||||
|
||||
void runSocketIOTest();
|
||||
|
||||
#endif /* defined(__TestCpp__SocketIOTest__) */
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue