2013-12-18 10:41:09 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2013-11-05 01:14:22 +08:00
|
|
|
|
2013-12-17 16:34:05 +08:00
|
|
|
#include "NewRendererTest.h"
|
2013-11-05 01:14:22 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
NewRendererTests::NewRendererTests()
|
2013-11-13 03:19:18 +08:00
|
|
|
{
|
2015-04-03 14:31:03 +08:00
|
|
|
ADD_TEST_CASE(NewSpriteTest);
|
|
|
|
ADD_TEST_CASE(GroupCommandTest);
|
|
|
|
ADD_TEST_CASE(NewClippingNodeTest);
|
|
|
|
ADD_TEST_CASE(NewDrawNodeTest);
|
|
|
|
ADD_TEST_CASE(NewCullingTest);
|
|
|
|
ADD_TEST_CASE(VBOFullTest);
|
|
|
|
ADD_TEST_CASE(CaptureScreenTest);
|
2013-11-13 03:19:18 +08:00
|
|
|
};
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string MultiSceneTest::title() const
|
2013-11-13 03:19:18 +08:00
|
|
|
{
|
2014-02-28 23:02:22 +08:00
|
|
|
return "New Renderer";
|
2013-11-13 03:19:18 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string MultiSceneTest::subtitle() const
|
2013-11-13 03:19:18 +08:00
|
|
|
{
|
2014-02-28 23:02:22 +08:00
|
|
|
return "MultiSceneTest";
|
2013-11-13 03:19:18 +08:00
|
|
|
}
|
|
|
|
|
2013-11-13 03:23:10 +08:00
|
|
|
NewSpriteTest::NewSpriteTest()
|
2013-11-05 01:14:22 +08:00
|
|
|
{
|
|
|
|
auto touchListener = EventListenerTouchAllAtOnce::create();
|
2013-11-13 03:23:10 +08:00
|
|
|
touchListener->onTouchesEnded = CC_CALLBACK_2(NewSpriteTest::onTouchesEnded, this);
|
2013-11-05 01:14:22 +08:00
|
|
|
|
2013-11-08 08:50:53 +08:00
|
|
|
createSpriteTest();
|
2013-11-05 01:14:22 +08:00
|
|
|
createNewSpriteTest();
|
|
|
|
}
|
|
|
|
|
2013-11-13 03:23:10 +08:00
|
|
|
NewSpriteTest::~NewSpriteTest()
|
2013-11-05 01:14:22 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-11-13 03:19:18 +08:00
|
|
|
void NewSpriteTest::createSpriteTest()
|
2013-11-05 01:14:22 +08:00
|
|
|
{
|
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
Sprite* parent = Sprite::create("Images/grossini.png");
|
2013-11-08 07:48:37 +08:00
|
|
|
parent->setPosition(winSize.width/4, winSize.height/2);
|
2013-11-05 01:14:22 +08:00
|
|
|
Sprite* child1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
child1->setPosition(0.0f, -20.0f);
|
|
|
|
Sprite* child2 = Sprite::create("Images/grossinis_sister2.png");
|
|
|
|
child2->setPosition(20.0f, -20.0f);
|
|
|
|
Sprite* child3 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
child3->setPosition(40.0f, -20.0f);
|
2013-11-08 07:48:37 +08:00
|
|
|
Sprite* child4 = Sprite::create("Images/grossinis_sister2.png");
|
2013-11-05 01:14:22 +08:00
|
|
|
child4->setPosition(60.0f, -20.0f);
|
2013-11-08 07:48:37 +08:00
|
|
|
Sprite* child5 = Sprite::create("Images/grossinis_sister2.png");
|
|
|
|
child5->setPosition(80.0f, -20.0f);
|
|
|
|
Sprite* child6 = Sprite::create("Images/grossinis_sister2.png");
|
|
|
|
child6->setPosition(100.0f, -20.0f);
|
|
|
|
Sprite* child7 = Sprite::create("Images/grossinis_sister2.png");
|
|
|
|
child7->setPosition(120.0f, -20.0f);
|
2013-11-05 01:14:22 +08:00
|
|
|
|
|
|
|
parent->addChild(child1);
|
|
|
|
parent->addChild(child2);
|
|
|
|
parent->addChild(child3);
|
|
|
|
parent->addChild(child4);
|
2013-11-08 07:48:37 +08:00
|
|
|
parent->addChild(child5);
|
|
|
|
parent->addChild(child6);
|
|
|
|
parent->addChild(child7);
|
2013-11-05 01:14:22 +08:00
|
|
|
addChild(parent);
|
|
|
|
}
|
|
|
|
|
2013-11-13 03:19:18 +08:00
|
|
|
void NewSpriteTest::createNewSpriteTest()
|
2013-11-05 01:14:22 +08:00
|
|
|
{
|
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
|
|
|
|
2013-12-23 21:07:25 +08:00
|
|
|
Sprite* parent = Sprite::create("Images/grossini.png");
|
2013-11-05 01:14:22 +08:00
|
|
|
parent->setPosition(winSize.width*2/3, winSize.height/2);
|
2013-12-23 21:07:25 +08:00
|
|
|
Sprite* child1 = Sprite::create("Images/grossinis_sister1.png");
|
2013-11-05 01:14:22 +08:00
|
|
|
child1->setPosition(0.0f, -20.0f);
|
2013-12-23 21:07:25 +08:00
|
|
|
Sprite* child2 = Sprite::create("Images/grossinis_sister2.png");
|
2013-11-05 01:14:22 +08:00
|
|
|
child2->setPosition(20.0f, -20.0f);
|
2013-12-23 21:07:25 +08:00
|
|
|
Sprite* child3 = Sprite::create("Images/grossinis_sister1.png");
|
2013-11-05 01:14:22 +08:00
|
|
|
child3->setPosition(40.0f, -20.0f);
|
2013-12-23 21:07:25 +08:00
|
|
|
Sprite* child4 = Sprite::create("Images/grossinis_sister2.png");
|
2013-11-05 01:14:22 +08:00
|
|
|
child4->setPosition(60.0f, -20.0f);
|
2013-12-23 21:07:25 +08:00
|
|
|
Sprite* child5 = Sprite::create("Images/grossinis_sister2.png");
|
2013-11-08 07:48:37 +08:00
|
|
|
child5->setPosition(80.0f, -20.0f);
|
2013-12-23 21:07:25 +08:00
|
|
|
Sprite* child6 = Sprite::create("Images/grossinis_sister2.png");
|
2013-11-08 07:48:37 +08:00
|
|
|
child6->setPosition(100.0f, -20.0f);
|
2013-12-23 21:07:25 +08:00
|
|
|
Sprite* child7 = Sprite::create("Images/grossinis_sister2.png");
|
2013-11-08 07:48:37 +08:00
|
|
|
child7->setPosition(120.0f, -20.0f);
|
2013-11-05 01:14:22 +08:00
|
|
|
|
|
|
|
parent->addChild(child1);
|
|
|
|
parent->addChild(child2);
|
|
|
|
parent->addChild(child3);
|
|
|
|
parent->addChild(child4);
|
2013-11-08 07:48:37 +08:00
|
|
|
parent->addChild(child5);
|
|
|
|
parent->addChild(child6);
|
|
|
|
parent->addChild(child7);
|
2013-11-05 01:14:22 +08:00
|
|
|
addChild(parent);
|
|
|
|
}
|
|
|
|
|
2013-11-13 03:19:18 +08:00
|
|
|
void NewSpriteTest::onTouchesEnded(const std::vector<Touch *> &touches, Event *event)
|
2013-11-05 01:14:22 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NewSpriteTest::title() const
|
2013-11-05 01:14:22 +08:00
|
|
|
{
|
2014-03-06 03:50:12 +08:00
|
|
|
return "Renderer";
|
2013-11-13 03:19:18 +08:00
|
|
|
}
|
2013-11-05 01:14:22 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NewSpriteTest::subtitle() const
|
2013-11-13 03:19:18 +08:00
|
|
|
{
|
|
|
|
return "SpriteTest";
|
2013-11-05 01:14:22 +08:00
|
|
|
}
|
2013-11-13 03:53:53 +08:00
|
|
|
|
2014-04-07 22:31:24 +08:00
|
|
|
class SpriteInGroupCommand : public Sprite
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
GroupCommand _spriteWrapperCommand;
|
|
|
|
public:
|
|
|
|
static SpriteInGroupCommand* create(const std::string& filename);
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
|
2014-04-07 22:31:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
SpriteInGroupCommand* SpriteInGroupCommand::create(const std::string &filename)
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
SpriteInGroupCommand* sprite = new (std::nothrow) SpriteInGroupCommand();
|
2014-04-07 22:31:24 +08:00
|
|
|
sprite->initWithFile(filename);
|
|
|
|
sprite->autorelease();
|
|
|
|
return sprite;
|
|
|
|
}
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
void SpriteInGroupCommand::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
2014-04-07 22:31:24 +08:00
|
|
|
{
|
|
|
|
CCASSERT(renderer, "Render is null");
|
|
|
|
_spriteWrapperCommand.init(_globalZOrder);
|
|
|
|
renderer->addCommand(&_spriteWrapperCommand);
|
|
|
|
renderer->pushGroup(_spriteWrapperCommand.getRenderQueueID());
|
2014-05-31 07:42:05 +08:00
|
|
|
Sprite::draw(renderer, transform, flags);
|
2014-04-07 22:31:24 +08:00
|
|
|
renderer->popGroup();
|
|
|
|
}
|
|
|
|
|
2014-04-07 22:02:43 +08:00
|
|
|
GroupCommandTest::GroupCommandTest()
|
|
|
|
{
|
2014-04-07 22:31:24 +08:00
|
|
|
auto sprite = SpriteInGroupCommand::create("Images/grossini.png");
|
2014-04-07 22:02:43 +08:00
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
|
|
|
sprite->setPosition(winSize.width/2,winSize.height/2);
|
|
|
|
addChild(sprite);
|
|
|
|
}
|
|
|
|
|
|
|
|
GroupCommandTest::~GroupCommandTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GroupCommandTest::title() const
|
|
|
|
{
|
|
|
|
return "Renderer";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GroupCommandTest::subtitle() const
|
|
|
|
{
|
|
|
|
return "GroupCommandTest: You should see a sprite";
|
|
|
|
}
|
|
|
|
|
2013-11-16 03:29:11 +08:00
|
|
|
NewClippingNodeTest::NewClippingNodeTest()
|
|
|
|
{
|
2013-11-16 09:32:29 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
2013-12-24 14:08:57 +08:00
|
|
|
auto clipper = ClippingNode::create();
|
2013-11-16 03:29:11 +08:00
|
|
|
clipper->setTag( kTagClipperNode );
|
|
|
|
clipper->setContentSize( Size(200, 200) );
|
2014-05-15 01:07:09 +08:00
|
|
|
clipper->setAnchorPoint( Vec2(0.5, 0.5) );
|
|
|
|
clipper->setPosition( Vec2(s.width / 2, s.height / 2) );
|
2013-11-19 07:52:47 +08:00
|
|
|
|
2013-11-16 03:29:11 +08:00
|
|
|
clipper->runAction(RepeatForever::create(RotateBy::create(1, 45)));
|
|
|
|
this->addChild(clipper);
|
|
|
|
|
2014-08-30 03:54:24 +08:00
|
|
|
// TODO: Fix draw node as clip node
|
2013-11-19 06:58:41 +08:00
|
|
|
// auto stencil = NewDrawNode::create();
|
2014-05-15 01:07:09 +08:00
|
|
|
// Vec2 rectangle[4];
|
|
|
|
// rectangle[0] = Vec2(0, 0);
|
|
|
|
// rectangle[1] = Vec2(clipper->getContentSize().width, 0);
|
|
|
|
// rectangle[2] = Vec2(clipper->getContentSize().width, clipper->getContentSize().height);
|
|
|
|
// rectangle[3] = Vec2(0, clipper->getContentSize().height);
|
2013-11-19 06:58:41 +08:00
|
|
|
//
|
|
|
|
// Color4F white(1, 1, 1, 1);
|
|
|
|
// stencil->drawPolygon(rectangle, 4, white, 1, white);
|
2013-11-16 09:32:29 +08:00
|
|
|
// clipper->setStencil(stencil);
|
2013-11-19 06:58:41 +08:00
|
|
|
|
2013-11-20 03:06:26 +08:00
|
|
|
//Test with alpha Test
|
2013-11-19 07:52:47 +08:00
|
|
|
clipper->setAlphaThreshold(0.05f);
|
2013-12-23 21:07:25 +08:00
|
|
|
auto stencil = Sprite::create("Images/grossini.png");
|
2013-11-19 06:58:41 +08:00
|
|
|
stencil->setPosition(s.width/2, s.height/2);
|
|
|
|
clipper->setStencil(stencil);
|
2013-11-16 03:29:11 +08:00
|
|
|
|
2013-12-23 21:07:25 +08:00
|
|
|
auto content = Sprite::create("Images/background2.png");
|
2013-11-16 03:29:11 +08:00
|
|
|
content->setTag( kTagContentNode );
|
2014-05-15 01:07:09 +08:00
|
|
|
content->setAnchorPoint( Vec2(0.5, 0.5) );
|
|
|
|
content->setPosition( Vec2(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2) );
|
2013-11-16 03:29:11 +08:00
|
|
|
clipper->addChild(content);
|
|
|
|
|
|
|
|
_scrolling = false;
|
|
|
|
|
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesBegan = CC_CALLBACK_2(NewClippingNodeTest::onTouchesBegan, this);
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(NewClippingNodeTest::onTouchesMoved, this);
|
|
|
|
listener->onTouchesEnded = CC_CALLBACK_2(NewClippingNodeTest::onTouchesEnded, this);
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
NewClippingNodeTest::~NewClippingNodeTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NewClippingNodeTest::title() const
|
2013-11-16 03:29:11 +08:00
|
|
|
{
|
|
|
|
return "New Render";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NewClippingNodeTest::subtitle() const
|
2013-11-16 03:29:11 +08:00
|
|
|
{
|
|
|
|
return "ClipNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewClippingNodeTest::onTouchesBegan(const std::vector<Touch *> &touches, Event *event)
|
|
|
|
{
|
|
|
|
Touch *touch = touches[0];
|
|
|
|
auto clipper = this->getChildByTag(kTagClipperNode);
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 point = clipper->convertToNodeSpace(Director::getInstance()->convertToGL(touch->getLocationInView()));
|
2013-11-16 03:29:11 +08:00
|
|
|
auto rect = Rect(0, 0, clipper->getContentSize().width, clipper->getContentSize().height);
|
|
|
|
_scrolling = rect.containsPoint(point);
|
|
|
|
_lastPoint = point;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewClippingNodeTest::onTouchesMoved(const std::vector<Touch *> &touches, Event *event)
|
|
|
|
{
|
|
|
|
if (!_scrolling) return;
|
|
|
|
Touch *touch = touches[0];
|
|
|
|
auto clipper = this->getChildByTag(kTagClipperNode);
|
|
|
|
auto point = clipper->convertToNodeSpace(Director::getInstance()->convertToGL(touch->getLocationInView()));
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 diff = point - _lastPoint;
|
2013-11-16 03:29:11 +08:00
|
|
|
auto content = clipper->getChildByTag(kTagContentNode);
|
|
|
|
content->setPosition(content->getPosition() + diff);
|
|
|
|
_lastPoint = point;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewClippingNodeTest::onTouchesEnded(const std::vector<Touch *> &touches, Event *event)
|
|
|
|
{
|
|
|
|
if (!_scrolling) return;
|
|
|
|
_scrolling = false;
|
|
|
|
}
|
2013-11-20 05:57:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* NewDrawNode
|
|
|
|
*/
|
|
|
|
NewDrawNodeTest::NewDrawNodeTest()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto parent = Node::create();
|
|
|
|
parent->setPosition(s.width/2, s.height/2);
|
|
|
|
addChild(parent);
|
|
|
|
|
2013-12-19 03:45:30 +08:00
|
|
|
auto rectNode = DrawNode::create();
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 rectangle[4];
|
|
|
|
rectangle[0] = Vec2(-50, -50);
|
|
|
|
rectangle[1] = Vec2(50, -50);
|
|
|
|
rectangle[2] = Vec2(50, 50);
|
|
|
|
rectangle[3] = Vec2(-50, 50);
|
2013-11-20 05:57:39 +08:00
|
|
|
|
|
|
|
Color4F white(1, 1, 1, 1);
|
|
|
|
rectNode->drawPolygon(rectangle, 4, white, 1, white);
|
|
|
|
parent->addChild(rectNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
NewDrawNodeTest::~NewDrawNodeTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NewDrawNodeTest::title() const
|
2013-11-20 05:57:39 +08:00
|
|
|
{
|
|
|
|
return "New Render";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NewDrawNodeTest::subtitle() const
|
2013-11-20 05:57:39 +08:00
|
|
|
{
|
|
|
|
return "DrawNode";
|
|
|
|
}
|
2013-11-27 10:35:23 +08:00
|
|
|
|
|
|
|
NewCullingTest::NewCullingTest()
|
|
|
|
{
|
2014-04-14 11:33:40 +08:00
|
|
|
Size size = Director::getInstance()->getWinSize();
|
|
|
|
auto sprite = Sprite::create("Images/btn-about-normal-vertical.png");
|
2014-04-15 07:46:19 +08:00
|
|
|
sprite->setRotation(5);
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2(size.width/2,size.height/3));
|
2014-04-14 11:33:40 +08:00
|
|
|
sprite->setScale(2);
|
|
|
|
addChild(sprite);
|
2014-04-15 22:21:04 +08:00
|
|
|
|
2014-04-14 11:33:40 +08:00
|
|
|
auto sprite2 = Sprite::create("Images/btn-about-normal-vertical.png");
|
|
|
|
sprite2->setRotation(-85);
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite2->setPosition(Vec2(size.width/2,size.height * 2/3));
|
2014-04-14 11:33:40 +08:00
|
|
|
sprite2->setScale(2);
|
|
|
|
addChild(sprite2);
|
2013-11-27 10:35:23 +08:00
|
|
|
|
2014-04-14 11:33:40 +08:00
|
|
|
auto listener = EventListenerTouchOneByOne::create();
|
2014-04-14 11:45:06 +08:00
|
|
|
listener->setSwallowTouches(true);
|
2013-11-27 14:30:38 +08:00
|
|
|
|
2014-04-14 11:45:06 +08:00
|
|
|
listener->onTouchBegan = CC_CALLBACK_2(NewCullingTest::onTouchBegan, this);
|
|
|
|
listener->onTouchMoved = CC_CALLBACK_2(NewCullingTest::onTouchMoved, this);
|
2014-04-14 11:33:40 +08:00
|
|
|
|
2014-04-14 11:45:06 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2014-04-14 11:33:40 +08:00
|
|
|
|
|
|
|
}
|
2013-11-27 14:30:38 +08:00
|
|
|
|
2014-04-14 11:33:40 +08:00
|
|
|
bool NewCullingTest::onTouchBegan(Touch* touch, Event *event)
|
|
|
|
{
|
2014-04-14 11:45:06 +08:00
|
|
|
auto pos = touch->getLocation();
|
|
|
|
_lastPos = pos;
|
|
|
|
return true;
|
2014-04-14 11:33:40 +08:00
|
|
|
}
|
2013-11-27 14:30:38 +08:00
|
|
|
|
2014-04-14 11:33:40 +08:00
|
|
|
void NewCullingTest::onTouchMoved(Touch* touch, Event *event)
|
2014-04-14 11:45:06 +08:00
|
|
|
{
|
|
|
|
auto pos = touch->getLocation();
|
2014-04-14 11:33:40 +08:00
|
|
|
|
2014-04-14 11:45:06 +08:00
|
|
|
auto offset = pos - _lastPos;
|
2014-04-14 11:33:40 +08:00
|
|
|
|
2014-04-14 11:45:06 +08:00
|
|
|
auto layerPos = getPosition();
|
|
|
|
auto newPos = layerPos + offset;
|
2014-04-14 11:33:40 +08:00
|
|
|
|
2014-04-14 11:45:06 +08:00
|
|
|
setPosition(newPos);
|
|
|
|
_lastPos = pos;
|
2013-11-27 10:35:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NewCullingTest::~NewCullingTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NewCullingTest::title() const
|
2013-11-27 10:35:23 +08:00
|
|
|
{
|
|
|
|
return "New Render";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NewCullingTest::subtitle() const
|
2013-11-27 10:35:23 +08:00
|
|
|
{
|
2014-04-14 11:33:40 +08:00
|
|
|
return "Drag the layer to test the result of culling";
|
2013-11-27 10:35:23 +08:00
|
|
|
}
|
|
|
|
|
2014-01-15 09:03:54 +08:00
|
|
|
VBOFullTest::VBOFullTest()
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getWinSize();
|
|
|
|
Node* parent = Node::create();
|
2014-10-16 18:30:01 +08:00
|
|
|
parent->setPosition(0,0);
|
2014-01-15 09:03:54 +08:00
|
|
|
addChild(parent);
|
|
|
|
|
2014-10-16 18:30:01 +08:00
|
|
|
for (int i=0; i< Renderer::VBO_SIZE / 3.9; ++i)
|
2014-01-15 09:03:54 +08:00
|
|
|
{
|
|
|
|
Sprite* sprite = Sprite::create("Images/grossini_dance_01.png");
|
2015-01-15 10:07:23 +08:00
|
|
|
sprite->setScale(0.1f, 0.1f);
|
2014-10-16 18:30:01 +08:00
|
|
|
float x = ((float)std::rand()) /RAND_MAX;
|
|
|
|
float y = ((float)std::rand()) /RAND_MAX;
|
|
|
|
sprite->setPosition(Vec2(x * s.width, y * s.height));
|
2014-01-15 09:03:54 +08:00
|
|
|
parent->addChild(sprite);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VBOFullTest::~VBOFullTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string VBOFullTest::title() const
|
|
|
|
{
|
|
|
|
return "New Renderer";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string VBOFullTest::subtitle() const
|
|
|
|
{
|
2014-01-15 09:06:22 +08:00
|
|
|
return "VBO full Test, everthing should render normally";
|
2014-01-15 09:11:32 +08:00
|
|
|
}
|
2014-05-13 16:23:35 +08:00
|
|
|
|
|
|
|
CaptureScreenTest::CaptureScreenTest()
|
|
|
|
{
|
2014-05-13 17:17:15 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2014-05-26 20:18:11 +08:00
|
|
|
Vec2 left(s.width / 4, s.height / 2);
|
|
|
|
Vec2 right(s.width / 4 * 3, s.height / 2);
|
2014-05-13 16:23:35 +08:00
|
|
|
|
2014-05-13 17:17:15 +08:00
|
|
|
auto sp1 = Sprite::create("Images/grossini.png");
|
|
|
|
sp1->setPosition(left);
|
2014-05-26 20:18:11 +08:00
|
|
|
auto move1 = MoveBy::create(1, Vec2(s.width/2, 0));
|
2014-05-14 10:40:56 +08:00
|
|
|
auto seq1 = RepeatForever::create(Sequence::create(move1, move1->reverse(), nullptr));
|
2014-05-13 17:17:15 +08:00
|
|
|
addChild(sp1);
|
|
|
|
sp1->runAction(seq1);
|
|
|
|
auto sp2 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
sp2->setPosition(right);
|
2014-05-26 20:18:11 +08:00
|
|
|
auto move2 = MoveBy::create(1, Vec2(-s.width/2, 0));
|
2014-05-14 10:40:56 +08:00
|
|
|
auto seq2 = RepeatForever::create(Sequence::create(move2, move2->reverse(), nullptr));
|
2014-05-13 17:17:15 +08:00
|
|
|
addChild(sp2);
|
|
|
|
sp2->runAction(seq2);
|
|
|
|
|
|
|
|
auto label1 = Label::createWithTTF(TTFConfig("fonts/arial.ttf"), "capture all");
|
2014-05-26 13:42:47 +08:00
|
|
|
auto mi1 = MenuItemLabel::create(label1, CC_CALLBACK_1(CaptureScreenTest::onCaptured, this));
|
|
|
|
auto menu = Menu::create(mi1, nullptr);
|
2014-05-13 17:17:15 +08:00
|
|
|
addChild(menu);
|
|
|
|
menu->setPosition(s.width / 2, s.height / 4);
|
2014-05-13 18:34:35 +08:00
|
|
|
|
2014-05-14 01:06:26 +08:00
|
|
|
_filename = "";
|
2014-05-13 16:23:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CaptureScreenTest::~CaptureScreenTest()
|
|
|
|
{
|
2014-05-19 01:12:56 +08:00
|
|
|
Director::getInstance()->getTextureCache()->removeTextureForKey(_filename);
|
2014-05-13 16:23:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CaptureScreenTest::title() const
|
|
|
|
{
|
2014-05-13 17:17:15 +08:00
|
|
|
return "New Renderer";
|
2014-05-13 16:23:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CaptureScreenTest::subtitle() const
|
|
|
|
{
|
2014-05-26 16:32:13 +08:00
|
|
|
return "Capture screen test, press the menu items to capture the screen";
|
2014-05-13 16:23:35 +08:00
|
|
|
}
|
|
|
|
|
2014-05-26 13:42:47 +08:00
|
|
|
void CaptureScreenTest::onCaptured(Ref*)
|
2014-05-13 16:23:35 +08:00
|
|
|
{
|
2014-05-14 01:06:26 +08:00
|
|
|
Director::getInstance()->getTextureCache()->removeTextureForKey(_filename);
|
2014-05-26 16:32:13 +08:00
|
|
|
removeChildByTag(childTag);
|
2014-05-14 01:06:26 +08:00
|
|
|
_filename = "CaptureScreenTest.png";
|
2014-05-27 14:29:52 +08:00
|
|
|
utils::captureScreen(CC_CALLBACK_2(CaptureScreenTest::afterCaptured, this), _filename);
|
2014-05-13 16:23:35 +08:00
|
|
|
}
|
|
|
|
|
2014-05-14 01:06:26 +08:00
|
|
|
void CaptureScreenTest::afterCaptured(bool succeed, const std::string& outputFile)
|
2014-05-13 16:23:35 +08:00
|
|
|
{
|
2014-05-13 17:17:15 +08:00
|
|
|
if (succeed)
|
|
|
|
{
|
2014-05-14 10:40:56 +08:00
|
|
|
auto sp = Sprite::create(outputFile);
|
2014-05-26 16:32:13 +08:00
|
|
|
addChild(sp, 0, childTag);
|
2014-05-14 10:40:56 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
|
|
|
sp->setPosition(s.width / 2, s.height / 2);
|
|
|
|
sp->setScale(0.25);
|
2014-05-14 01:06:26 +08:00
|
|
|
_filename = outputFile;
|
2014-05-13 17:17:15 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-26 16:24:57 +08:00
|
|
|
log("Capture screen failed.");
|
2014-05-13 17:17:15 +08:00
|
|
|
}
|
2014-05-14 16:25:47 +08:00
|
|
|
}
|