mirror of https://github.com/axmolengine/axmol.git
Adds more tests cases for Node
Adds more tests cases for Node
This commit is contained in:
parent
1dc169b19f
commit
95b7196a2a
|
@ -25,6 +25,7 @@ static int sceneIdx = -1;
|
||||||
|
|
||||||
static std::function<Layer*()> createFunctions[] =
|
static std::function<Layer*()> createFunctions[] =
|
||||||
{
|
{
|
||||||
|
CL(CameraTest1),
|
||||||
CL(CameraTest2),
|
CL(CameraTest2),
|
||||||
CL(CameraCenterTest),
|
CL(CameraCenterTest),
|
||||||
CL(Test2),
|
CL(Test2),
|
||||||
|
@ -34,6 +35,7 @@ static std::function<Layer*()> createFunctions[] =
|
||||||
CL(StressTest1),
|
CL(StressTest1),
|
||||||
CL(StressTest2),
|
CL(StressTest2),
|
||||||
CL(NodeToWorld),
|
CL(NodeToWorld),
|
||||||
|
CL(NodeToWorld3D),
|
||||||
CL(SchedulerTest1),
|
CL(SchedulerTest1),
|
||||||
CL(CameraOrbitTest),
|
CL(CameraOrbitTest),
|
||||||
CL(CameraZoomTest),
|
CL(CameraZoomTest),
|
||||||
|
@ -492,6 +494,56 @@ std::string NodeToWorld::title() const
|
||||||
return "nodeToParent transform";
|
return "nodeToParent transform";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// NodeToWorld3D
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
NodeToWorld3D::NodeToWorld3D()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// This code tests that nodeToParent works OK:
|
||||||
|
// - It tests different anchor Points
|
||||||
|
// - It tests different children anchor points
|
||||||
|
|
||||||
|
Size s = Director::getInstance()->getWinSize();
|
||||||
|
auto parent = Node::create();
|
||||||
|
parent->setContentSize(s);
|
||||||
|
parent->setAnchorPoint(Point(0.5, 0.5));
|
||||||
|
parent->setPosition(s.width/2, s.height/2);
|
||||||
|
this->addChild(parent);
|
||||||
|
|
||||||
|
auto back = Sprite::create(s_back3);
|
||||||
|
parent->addChild( back, -10);
|
||||||
|
back->setAnchorPoint( Point(0,0) );
|
||||||
|
auto backSize = back->getContentSize();
|
||||||
|
|
||||||
|
auto item = MenuItemImage::create(s_PlayNormal, s_PlaySelect);
|
||||||
|
auto menu = Menu::create(item, NULL);
|
||||||
|
menu->alignItemsVertically();
|
||||||
|
menu->setPosition( Point(backSize.width/2, backSize.height/2));
|
||||||
|
back->addChild(menu);
|
||||||
|
|
||||||
|
auto rot = RotateBy::create(5, 360);
|
||||||
|
auto fe = RepeatForever::create( rot);
|
||||||
|
item->runAction( fe );
|
||||||
|
|
||||||
|
auto move = MoveBy::create(3, Point(200,0));
|
||||||
|
auto move_back = move->reverse();
|
||||||
|
auto seq = Sequence::create( move, move_back, NULL);
|
||||||
|
auto fe2 = RepeatForever::create(seq);
|
||||||
|
back->runAction(fe2);
|
||||||
|
|
||||||
|
auto orbit = OrbitCamera::create(10, 0, 1, 0, 360, 0, 90);
|
||||||
|
parent->runAction(orbit);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string NodeToWorld3D::title() const
|
||||||
|
{
|
||||||
|
return "nodeToParent transform in 3D";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// CameraOrbitTest
|
// CameraOrbitTest
|
||||||
|
@ -828,12 +880,10 @@ std::string NodeNonOpaqueTest::subtitle() const
|
||||||
return "Node rendered with GL_BLEND enabled";
|
return "Node rendered with GL_BLEND enabled";
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// CameraTest2
|
|
||||||
//
|
|
||||||
//------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// MySprite: Used by CameraTest1 and CameraTest2
|
||||||
|
//
|
||||||
class MySprite : public Sprite
|
class MySprite : public Sprite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -852,7 +902,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CustomCommand _customCommand;
|
CustomCommand _customCommand;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void MySprite::draw()
|
void MySprite::draw()
|
||||||
|
@ -892,6 +942,58 @@ void MySprite::onDraw()
|
||||||
CHECK_GL_ERROR_DEBUG();
|
CHECK_GL_ERROR_DEBUG();
|
||||||
CC_INCREMENT_GL_DRAWS(1);
|
CC_INCREMENT_GL_DRAWS(1);
|
||||||
}
|
}
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// CameraTest1
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
|
void CameraTest1::onEnter()
|
||||||
|
{
|
||||||
|
TestCocosNodeDemo::onEnter();
|
||||||
|
Director::getInstance()->setProjection(Director::Projection::_3D);
|
||||||
|
Director::getInstance()->setDepthTest(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CameraTest1::onExit()
|
||||||
|
{
|
||||||
|
Director::getInstance()->setProjection(Director::Projection::_2D);
|
||||||
|
TestCocosNodeDemo::onExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
CameraTest1::CameraTest1()
|
||||||
|
{
|
||||||
|
auto s = Director::getInstance()->getWinSize();
|
||||||
|
|
||||||
|
_sprite1 = MySprite::create(s_back3);
|
||||||
|
addChild( _sprite1 );
|
||||||
|
_sprite1->setPosition( Point(1*s.width/4, s.height/2) );
|
||||||
|
_sprite1->setScale(0.5);
|
||||||
|
|
||||||
|
_sprite2 = Sprite::create(s_back3);
|
||||||
|
addChild( _sprite2 );
|
||||||
|
_sprite2->setPosition( Point(3*s.width/4, s.height/2) );
|
||||||
|
_sprite2->setScale(0.5);
|
||||||
|
|
||||||
|
auto camera = OrbitCamera::create(10, 0, 1, 0, 360, 0, 0);
|
||||||
|
_sprite1->runAction( camera );
|
||||||
|
_sprite2->runAction( camera->clone() );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CameraTest1::title() const
|
||||||
|
{
|
||||||
|
return "Camera Test 1";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CameraTest1::subtitle() const
|
||||||
|
{
|
||||||
|
return "Both images should rotate with a 3D effect";
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// CameraTest2
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------
|
||||||
void CameraTest2::onEnter()
|
void CameraTest2::onEnter()
|
||||||
{
|
{
|
||||||
TestCocosNodeDemo::onEnter();
|
TestCocosNodeDemo::onEnter();
|
||||||
|
|
|
@ -110,6 +110,16 @@ protected:
|
||||||
NodeToWorld();
|
NodeToWorld();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class NodeToWorld3D : public TestCocosNodeDemo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CREATE_FUNC(NodeToWorld3D);
|
||||||
|
virtual std::string title() const override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
NodeToWorld3D();
|
||||||
|
};
|
||||||
|
|
||||||
class CameraOrbitTest : public TestCocosNodeDemo
|
class CameraOrbitTest : public TestCocosNodeDemo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -148,6 +158,22 @@ protected:
|
||||||
CameraCenterTest();
|
CameraCenterTest();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CameraTest1 : public TestCocosNodeDemo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CREATE_FUNC(CameraTest1);
|
||||||
|
virtual std::string title() const override;
|
||||||
|
virtual std::string subtitle() const override;
|
||||||
|
virtual void onEnter() override;
|
||||||
|
virtual void onExit() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CameraTest1();
|
||||||
|
|
||||||
|
Sprite *_sprite1;
|
||||||
|
Sprite *_sprite2;
|
||||||
|
};
|
||||||
|
|
||||||
class CameraTest2 : public TestCocosNodeDemo
|
class CameraTest2 : public TestCocosNodeDemo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -163,7 +189,6 @@ protected:
|
||||||
|
|
||||||
Sprite *_sprite1;
|
Sprite *_sprite1;
|
||||||
Sprite *_sprite2;
|
Sprite *_sprite2;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConvertToNode : public TestCocosNodeDemo
|
class ConvertToNode : public TestCocosNodeDemo
|
||||||
|
|
Loading…
Reference in New Issue