2010-11-18 14:50:28 +08:00
|
|
|
#include "LayerTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
|
2010-08-31 17:03:58 +08:00
|
|
|
enum
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
kTagLayer = 1,
|
2010-08-31 17:03:58 +08:00
|
|
|
};
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
LayerTests::LayerTests()
|
|
|
|
{
|
|
|
|
ADD_TEST_CASE(LayerTestCascadingOpacityA);
|
|
|
|
ADD_TEST_CASE(LayerTestCascadingOpacityB);
|
|
|
|
ADD_TEST_CASE(LayerTestCascadingOpacityC);
|
|
|
|
ADD_TEST_CASE(LayerTestCascadingColorA);
|
|
|
|
ADD_TEST_CASE(LayerTestCascadingColorB);
|
|
|
|
ADD_TEST_CASE(LayerTestCascadingColorC);
|
|
|
|
ADD_TEST_CASE(LayerTest1);
|
|
|
|
ADD_TEST_CASE(LayerTest2);
|
|
|
|
ADD_TEST_CASE(LayerTestBlend);
|
|
|
|
ADD_TEST_CASE(LayerGradientTest);
|
|
|
|
ADD_TEST_CASE(LayerGradientTest2);
|
|
|
|
ADD_TEST_CASE(LayerGradientTest3);
|
|
|
|
ADD_TEST_CASE(LayerIgnoreAnchorPointPos);
|
|
|
|
ADD_TEST_CASE(LayerIgnoreAnchorPointRot);
|
|
|
|
ADD_TEST_CASE(LayerIgnoreAnchorPointScale);
|
|
|
|
ADD_TEST_CASE(LayerExtendedBlendOpacityTest);
|
|
|
|
ADD_TEST_CASE(LayerBug3162A);
|
|
|
|
ADD_TEST_CASE(LayerBug3162B);
|
|
|
|
ADD_TEST_CASE(LayerColorOccludeBug);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
2014-03-26 14:54:50 +08:00
|
|
|
// Cascading support extensions
|
2013-02-28 16:03:55 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
static void setEnableRecursiveCascading(Node* node, bool enable)
|
2013-02-28 16:03:55 +08:00
|
|
|
{
|
2013-12-06 18:07:16 +08:00
|
|
|
node->setCascadeColorEnabled(enable);
|
|
|
|
node->setCascadeOpacityEnabled(enable);
|
2013-02-28 16:45:59 +08:00
|
|
|
|
2013-12-17 17:45:29 +08:00
|
|
|
auto& children = node->getChildren();
|
2013-12-20 05:34:41 +08:00
|
|
|
for(const auto &child : children) {
|
2013-02-28 16:45:59 +08:00
|
|
|
setEnableRecursiveCascading(child, enable);
|
2013-12-20 05:34:41 +08:00
|
|
|
}
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2015-04-22 10:20:21 +08:00
|
|
|
std::string LayerTest::title() const
|
|
|
|
{
|
|
|
|
return "Layer Test";
|
|
|
|
}
|
|
|
|
|
2013-02-28 16:45:59 +08:00
|
|
|
// LayerTestCascadingOpacityA
|
|
|
|
void LayerTestCascadingOpacityA::onEnter()
|
2013-02-28 16:03:55 +08:00
|
|
|
{
|
2013-02-28 16:45:59 +08:00
|
|
|
LayerTest::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-12-06 18:07:16 +08:00
|
|
|
auto layer1 = Layer::create();
|
2013-02-28 16:45:59 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
|
2014-03-28 10:28:44 +08:00
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
sister1->setPosition( Vec2( s.width*1/3, s.height/2));
|
|
|
|
sister2->setPosition( Vec2( s.width*2/3, s.height/2));
|
|
|
|
label->setPosition( Vec2( s.width/2, s.height/2));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->runAction(
|
2013-11-14 09:36:33 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
FadeTo::create(4, 0),
|
|
|
|
FadeTo::create(4, 255),
|
|
|
|
DelayTime::create(1),
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr)));
|
2013-11-14 09:36:33 +08:00
|
|
|
|
2013-02-28 16:45:59 +08:00
|
|
|
sister1->runAction(
|
2013-11-14 09:36:33 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
FadeTo::create(2, 0),
|
|
|
|
FadeTo::create(2, 255),
|
|
|
|
FadeTo::create(2, 0),
|
|
|
|
FadeTo::create(2, 255),
|
|
|
|
DelayTime::create(1),
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr)));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
// Enable cascading in scene
|
|
|
|
setEnableRecursiveCascading(this, true);
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string LayerTestCascadingOpacityA::subtitle() const
|
2013-02-28 16:03:55 +08:00
|
|
|
{
|
2013-12-06 18:07:16 +08:00
|
|
|
return "Layer: cascading opacity";
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
// LayerTestCascadingOpacityB
|
|
|
|
void LayerTestCascadingOpacityB::onEnter()
|
2013-02-28 16:03:55 +08:00
|
|
|
{
|
2013-02-28 16:45:59 +08:00
|
|
|
LayerTest::onEnter();
|
2013-02-28 16:03:55 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto layer1 = LayerColor::create(Color4B(192, 0, 0, 255), s.width, s.height/2);
|
2013-02-28 16:45:59 +08:00
|
|
|
layer1->setCascadeColorEnabled(false);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
layer1->setPosition( Vec2(0, s.height/2));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
|
2014-03-28 10:28:44 +08:00
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
sister1->setPosition( Vec2( s.width*1/3, 0));
|
|
|
|
sister2->setPosition( Vec2( s.width*2/3, 0));
|
|
|
|
label->setPosition( Vec2( s.width/2, 0));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->runAction(
|
2013-06-20 14:17:10 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
FadeTo::create(4, 0),
|
|
|
|
FadeTo::create(4, 255),
|
|
|
|
DelayTime::create(1),
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr)));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
sister1->runAction(
|
2013-06-20 14:17:10 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
FadeTo::create(2, 0),
|
|
|
|
FadeTo::create(2, 255),
|
|
|
|
FadeTo::create(2, 0),
|
|
|
|
FadeTo::create(2, 255),
|
|
|
|
DelayTime::create(1),
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr)));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
// Enable cascading in scene
|
|
|
|
setEnableRecursiveCascading(this, true);
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string LayerTestCascadingOpacityB::subtitle() const
|
2013-02-28 16:03:55 +08:00
|
|
|
{
|
2013-02-28 16:45:59 +08:00
|
|
|
return "CCLayerColor: cascading opacity";
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
// LayerTestCascadingOpacityC
|
|
|
|
void LayerTestCascadingOpacityC::onEnter()
|
2013-02-28 16:03:55 +08:00
|
|
|
{
|
2013-02-28 16:45:59 +08:00
|
|
|
LayerTest::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto layer1 = LayerColor::create(Color4B(192, 0, 0, 255), s.width, s.height/2);
|
2013-02-28 16:45:59 +08:00
|
|
|
layer1->setCascadeColorEnabled(false);
|
|
|
|
layer1->setCascadeOpacityEnabled(false);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
layer1->setPosition( Vec2(0, s.height/2));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
|
2014-03-28 10:28:44 +08:00
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
sister1->setPosition( Vec2( s.width*1/3, 0));
|
|
|
|
sister2->setPosition( Vec2( s.width*2/3, 0));
|
|
|
|
label->setPosition( Vec2( s.width/2, 0));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->runAction(
|
2013-06-20 14:17:10 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
FadeTo::create(4, 0),
|
|
|
|
FadeTo::create(4, 255),
|
|
|
|
DelayTime::create(1),
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr)));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
sister1->runAction(
|
2013-06-20 14:17:10 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
FadeTo::create(2, 0),
|
|
|
|
FadeTo::create(2, 255),
|
|
|
|
FadeTo::create(2, 0),
|
|
|
|
FadeTo::create(2, 255),
|
|
|
|
DelayTime::create(1),
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr)));
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string LayerTestCascadingOpacityC::subtitle() const
|
2013-02-28 16:03:55 +08:00
|
|
|
{
|
2013-02-28 16:45:59 +08:00
|
|
|
return "CCLayerColor: non-cascading opacity";
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-26 14:54:50 +08:00
|
|
|
//// Example LayerTestCascadingColor
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
// LayerTestCascadingColorA
|
|
|
|
void LayerTestCascadingColorA::onEnter()
|
2013-02-28 16:03:55 +08:00
|
|
|
{
|
2013-02-28 16:45:59 +08:00
|
|
|
LayerTest::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-12-06 18:07:16 +08:00
|
|
|
auto layer1 = Layer::create();
|
2013-02-28 16:45:59 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
|
2014-03-28 10:28:44 +08:00
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
sister1->setPosition( Vec2( s.width*1/3, s.height/2));
|
|
|
|
sister2->setPosition( Vec2( s.width*2/3, s.height/2));
|
|
|
|
label->setPosition( Vec2( s.width/2, s.height/2));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->runAction(
|
2013-06-20 14:17:10 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
TintTo::create(6, 255, 0, 255),
|
|
|
|
TintTo::create(6, 255, 255, 255),
|
|
|
|
DelayTime::create(1),
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr)));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
sister1->runAction(
|
2013-06-20 14:17:10 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
TintTo::create(2, 255, 255, 0),
|
|
|
|
TintTo::create(2, 255, 255, 255),
|
|
|
|
TintTo::create(2, 0, 255, 255),
|
|
|
|
TintTo::create(2, 255, 255, 255),
|
|
|
|
TintTo::create(2, 255, 0, 255),
|
|
|
|
TintTo::create(2, 255, 255, 255),
|
|
|
|
DelayTime::create(1),
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr)));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
// Enable cascading in scene
|
|
|
|
setEnableRecursiveCascading(this, true);
|
|
|
|
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string LayerTestCascadingColorA::subtitle() const
|
2013-02-28 16:03:55 +08:00
|
|
|
{
|
2013-12-06 18:07:16 +08:00
|
|
|
return "Layer: cascading color";
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
// LayerTestCascadingColorB
|
|
|
|
void LayerTestCascadingColorB::onEnter()
|
2013-02-28 16:03:55 +08:00
|
|
|
{
|
2013-02-28 16:45:59 +08:00
|
|
|
LayerTest::onEnter();
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto layer1 = LayerColor::create(Color4B(255, 255, 255, 255), s.width, s.height/2);
|
2013-02-28 16:45:59 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
layer1->setPosition( Vec2(0, s.height/2));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
|
2014-03-28 10:28:44 +08:00
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
sister1->setPosition( Vec2( s.width*1/3, 0));
|
|
|
|
sister2->setPosition( Vec2( s.width*2/3, 0));
|
|
|
|
label->setPosition( Vec2( s.width/2, 0));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->runAction(
|
2013-06-20 14:17:10 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
TintTo::create(6, 255, 0, 255),
|
|
|
|
TintTo::create(6, 255, 255, 255),
|
|
|
|
DelayTime::create(1),
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr)));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
sister1->runAction(
|
2013-06-20 14:17:10 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
TintTo::create(2, 255, 255, 0),
|
|
|
|
TintTo::create(2, 255, 255, 255),
|
|
|
|
TintTo::create(2, 0, 255, 255),
|
|
|
|
TintTo::create(2, 255, 255, 255),
|
|
|
|
TintTo::create(2, 255, 0, 255),
|
|
|
|
TintTo::create(2, 255, 255, 255),
|
|
|
|
DelayTime::create(1),
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr)));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
// Enable cascading in scene
|
|
|
|
setEnableRecursiveCascading(this, true);
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string LayerTestCascadingColorB::subtitle() const
|
2013-02-28 16:03:55 +08:00
|
|
|
{
|
2013-02-28 16:45:59 +08:00
|
|
|
return "CCLayerColor: cascading color";
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
// LayerTestCascadingColorC
|
|
|
|
void LayerTestCascadingColorC::onEnter()
|
2013-02-28 16:03:55 +08:00
|
|
|
{
|
2013-02-28 16:45:59 +08:00
|
|
|
LayerTest::onEnter();
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto layer1 = LayerColor::create(Color4B(255, 255, 255, 255), s.width, s.height/2);
|
2013-02-28 16:45:59 +08:00
|
|
|
layer1->setCascadeColorEnabled(false);
|
2014-05-15 01:07:09 +08:00
|
|
|
layer1->setPosition( Vec2(0, s.height/2));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
|
2014-03-28 10:28:44 +08:00
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
sister1->setPosition( Vec2( s.width*1/3, 0));
|
|
|
|
sister2->setPosition( Vec2( s.width*2/3, 0));
|
|
|
|
label->setPosition( Vec2( s.width/2, 0));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->runAction(
|
2013-06-20 14:17:10 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
TintTo::create(6, 255, 0, 255),
|
|
|
|
TintTo::create(6, 255, 255, 255),
|
|
|
|
DelayTime::create(1),
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr)));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
sister1->runAction(
|
2013-06-20 14:17:10 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
TintTo::create(2, 255, 255, 0),
|
|
|
|
TintTo::create(2, 255, 255, 255),
|
|
|
|
TintTo::create(2, 0, 255, 255),
|
|
|
|
TintTo::create(2, 255, 255, 255),
|
|
|
|
TintTo::create(2, 255, 0, 255),
|
|
|
|
TintTo::create(2, 255, 255, 255),
|
|
|
|
DelayTime::create(1),
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr)));
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string LayerTestCascadingColorC::subtitle() const
|
2013-02-28 16:03:55 +08:00
|
|
|
{
|
2013-02-28 16:45:59 +08:00
|
|
|
return "CCLayerColor: non-cascading color";
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2010-08-31 17:03:58 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// LayerTest1
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void LayerTest1::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
LayerTest::onEnter();
|
|
|
|
|
2013-10-23 16:14:03 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesBegan = CC_CALLBACK_2(LayerTest1::onTouchesBegan, this);
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(LayerTest1::onTouchesMoved, this);
|
|
|
|
listener->onTouchesEnded = CC_CALLBACK_2(LayerTest1::onTouchesEnded, this);
|
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto layer = LayerColor::create( Color4B(0xFF, 0x00, 0x00, 0x80), 200, 200);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
layer->ignoreAnchorPointForPosition(false);
|
2014-05-15 01:07:09 +08:00
|
|
|
layer->setPosition( Vec2(s.width/2, s.height/2) );
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(layer, 1, kTagLayer);
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void LayerTest1::updateSize(Vec2 &touchLocation)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto newSize = Size( fabs(touchLocation.x - s.width/2)*2, fabs(touchLocation.y - s.height/2)*2);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto l = (LayerColor*) getChildByTag(kTagLayer);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
l->setContentSize( newSize );
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void LayerTest1::onTouchesBegan(const std::vector<Touch*>& touches, Event *event)
|
2010-08-31 17:03:58 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
onTouchesMoved(touches, event);
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void LayerTest1::onTouchesMoved(const std::vector<Touch*>& touches, Event *event)
|
2010-08-31 17:03:58 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
auto touchLocation = touches[0]->getLocation();
|
2012-03-22 13:59:47 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
updateSize(touchLocation);
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void LayerTest1::onTouchesEnded(const std::vector<Touch*>& touches, Event *event)
|
2010-08-31 17:03:58 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
onTouchesMoved(touches, event);
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string LayerTest1::subtitle() const
|
2010-08-31 17:03:58 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ColorLayer resize (tap & move)";
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// LayerTest2
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void LayerTest2::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
LayerTest::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto layer1 = LayerColor::create( Color4B(255, 255, 0, 80), 100, 300);
|
2014-05-15 01:07:09 +08:00
|
|
|
layer1->setPosition(Vec2(s.width/3, s.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
layer1->ignoreAnchorPointForPosition(false);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(layer1, 1);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer2 = LayerColor::create( Color4B(0, 0, 255, 255), 100, 300);
|
2014-05-15 01:07:09 +08:00
|
|
|
layer2->setPosition(Vec2((s.width/3)*2, s.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
layer2->ignoreAnchorPointForPosition(false);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(layer2, 1);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto actionTint = TintBy::create(2, -255, -127, 0);
|
|
|
|
auto actionTintBack = actionTint->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq1 = Sequence::create( actionTint, actionTintBack, nullptr);
|
2012-04-19 14:35:52 +08:00
|
|
|
layer1->runAction(seq1);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto actionFade = FadeOut::create(2.0f);
|
|
|
|
auto actionFadeBack = actionFade->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq2 = Sequence::create(actionFade, actionFadeBack, nullptr);
|
2012-04-19 14:35:52 +08:00
|
|
|
layer2->runAction(seq2);
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string LayerTest2::subtitle() const
|
2010-08-31 17:03:58 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ColorLayer: fade and tint";
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// LayerTestBlend
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
2010-11-18 14:50:28 +08:00
|
|
|
LayerTestBlend::LayerTestBlend()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto layer1 = LayerColor::create( Color4B(255, 255, 255, 80) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sister1 = Sprite::create(s_pathSister1);
|
|
|
|
auto sister2 = Sprite::create(s_pathSister2);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
addChild(sister1);
|
|
|
|
addChild(sister2);
|
|
|
|
addChild(layer1, 100, kTagLayer);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
sister1->setPosition( Vec2( s.width*1/3, s.height/2) );
|
|
|
|
sister2->setPosition( Vec2( s.width*2/3, s.height/2) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-10-04 00:38:36 +08:00
|
|
|
schedule( CC_SCHEDULE_SELECTOR(LayerTestBlend::newBlend), 1.0f);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void LayerTestBlend::newBlend(float dt)
|
2010-11-18 14:50:28 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = (LayerColor*)getChildByTag(kTagLayer);
|
2010-11-18 14:50:28 +08:00
|
|
|
|
|
|
|
GLenum src;
|
|
|
|
GLenum dst;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if( layer->getBlendFunc().dst == GL_ZERO )
|
2010-11-18 14:50:28 +08:00
|
|
|
{
|
2012-03-22 13:59:47 +08:00
|
|
|
src = GL_SRC_ALPHA;
|
|
|
|
dst = GL_ONE_MINUS_SRC_ALPHA;
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
else
|
2010-11-18 14:50:28 +08:00
|
|
|
{
|
|
|
|
src = GL_ONE_MINUS_DST_COLOR;
|
|
|
|
dst = GL_ZERO;
|
|
|
|
}
|
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
BlendFunc bf = {src, dst};
|
2010-11-18 14:50:28 +08:00
|
|
|
layer->setBlendFunc( bf );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-28 23:02:22 +08:00
|
|
|
std::string LayerTestBlend::subtitle() const
|
2010-11-18 14:50:28 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "ColorLayer: blend";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
2011-02-23 16:47:25 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
2013-06-29 10:02:10 +08:00
|
|
|
// LayerGradientTest
|
2011-02-23 16:47:25 +08:00
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2013-06-20 13:43:40 +08:00
|
|
|
LayerGradientTest::LayerGradientTest()
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
auto layer1 = LayerGradient::create(Color4B(255,0,0,255), Color4B(0,255,0,255), Vec2(0.9f, 0.9f));
|
2012-04-08 14:16:29 +08:00
|
|
|
addChild(layer1, 0, kTagLayer);
|
|
|
|
|
2013-10-23 16:14:03 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(LayerGradientTest::onTouchesMoved, this);
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label1 = Label::createWithTTF("Compressed Interpolation: Enabled", "fonts/Marker Felt.ttf", 26);
|
|
|
|
auto label2 = Label::createWithTTF("Compressed Interpolation: Disabled", "fonts/Marker Felt.ttf", 26);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto item1 = MenuItemLabel::create(label1);
|
|
|
|
auto item2 = MenuItemLabel::create(label2);
|
2014-07-10 00:45:27 +08:00
|
|
|
auto item = MenuItemToggle::createWithCallback( CC_CALLBACK_1(LayerGradientTest::toggleItem, this), item1, item2, nullptr);
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto menu = Menu::create(item, nullptr);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(menu);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
menu->setPosition(Vec2(s.width / 2, 100));
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void LayerGradientTest::toggleItem(Ref *sender)
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto gradient = static_cast<LayerGradient*>( getChildByTag(kTagLayer) );
|
2012-06-15 16:47:30 +08:00
|
|
|
gradient->setCompressedInterpolation(! gradient->isCompressedInterpolation());
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void LayerGradientTest::onTouchesMoved(const std::vector<Touch*>& touches, Event *event)
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
auto touch = touches[0];
|
2013-08-16 16:05:27 +08:00
|
|
|
auto start = touch->getLocation();
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
auto diff = Vec2(s.width/2,s.height/2) - start;
|
2014-05-01 01:10:18 +08:00
|
|
|
diff = diff.getNormalized();
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto gradient = static_cast<LayerGradient*>( getChildByTag(1) );
|
2012-04-08 14:16:29 +08:00
|
|
|
gradient->setVector(diff);
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string LayerGradientTest::title() const
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2013-06-20 13:43:40 +08:00
|
|
|
return "LayerGradientTest";
|
2011-02-23 16:47:25 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string LayerGradientTest::subtitle() const
|
2011-07-06 14:56:05 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Touch the screen and move your finger";
|
2011-07-06 14:56:05 +08:00
|
|
|
}
|
|
|
|
|
2013-06-29 10:02:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// LayerGradientTest2
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
LayerGradientTest2::LayerGradientTest2()
|
|
|
|
{
|
2014-03-27 10:55:41 +08:00
|
|
|
auto layer = LayerGradient::create(Color4B(255,0,0,255), Color4B(255,255,0,255));
|
2013-06-29 10:02:10 +08:00
|
|
|
addChild(layer);
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string LayerGradientTest2::title() const
|
2013-06-29 10:02:10 +08:00
|
|
|
{
|
|
|
|
return "LayerGradientTest 2";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string LayerGradientTest2::subtitle() const
|
2013-06-29 10:02:10 +08:00
|
|
|
{
|
|
|
|
return "You should see a gradient";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// LayerGradientTest3
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
LayerGradientTest3::LayerGradientTest3()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer1 = LayerGradient::create(Color4B(255,0,0,255), Color4B(255,255,0,255));
|
2013-06-29 10:02:10 +08:00
|
|
|
addChild(layer1);
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string LayerGradientTest3::title() const
|
2013-06-29 10:02:10 +08:00
|
|
|
{
|
|
|
|
return "LayerGradientTest 3";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string LayerGradientTest3::subtitle() const
|
2013-06-29 10:02:10 +08:00
|
|
|
{
|
|
|
|
return "You should see a gradient";
|
|
|
|
}
|
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
// LayerIgnoreAnchorPointPos
|
|
|
|
|
|
|
|
#define kLayerIgnoreAnchorPoint 1000
|
|
|
|
|
|
|
|
void LayerIgnoreAnchorPointPos::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto l = LayerColor::create(Color4B(255, 0, 0, 255), 150, 150);
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
l->setAnchorPoint(Vec2(0.5f, 0.5f));
|
|
|
|
l->setPosition(Vec2( s.width/2, s.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
auto move = MoveBy::create(2, Vec2(100,2));
|
2013-08-16 16:05:27 +08:00
|
|
|
auto back = (MoveBy *)move->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq = Sequence::create(move, back, nullptr);
|
2013-06-20 14:17:10 +08:00
|
|
|
l->runAction(RepeatForever::create(seq));
|
2012-06-15 15:10:40 +08:00
|
|
|
this->addChild(l, 0, kLayerIgnoreAnchorPoint);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto child = Sprite::create("Images/grossini.png");
|
2012-06-15 15:10:40 +08:00
|
|
|
l->addChild(child);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto lsize = l->getContentSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
child->setPosition(Vec2(lsize.width/2, lsize.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto item = MenuItemFont::create("Toggle ignore anchor point", CC_CALLBACK_1(LayerIgnoreAnchorPointPos::onToggle, this));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto menu = Menu::create(item, nullptr);
|
2012-06-15 15:10:40 +08:00
|
|
|
this->addChild(menu);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
menu->setPosition(Vec2(s.width/2, s.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void LayerIgnoreAnchorPointPos::onToggle(Ref* pObject)
|
2012-06-15 15:10:40 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = this->getChildByTag(kLayerIgnoreAnchorPoint);
|
2013-07-23 08:25:44 +08:00
|
|
|
bool ignore = layer->isIgnoreAnchorPointForPosition();
|
|
|
|
layer->ignoreAnchorPointForPosition(! ignore);
|
2012-06-15 15:10:40 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string LayerIgnoreAnchorPointPos::title() const
|
2012-06-12 15:14:01 +08:00
|
|
|
{
|
|
|
|
return "IgnoreAnchorPoint - Position";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string LayerIgnoreAnchorPointPos::subtitle() const
|
2012-06-15 15:10:40 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
return "Ignoring Anchor Vec2 for position";
|
2012-06-15 15:10:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// LayerIgnoreAnchorPointRot
|
|
|
|
|
|
|
|
void LayerIgnoreAnchorPointRot::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto l = LayerColor::create(Color4B(255, 0, 0, 255), 200, 200);
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
l->setAnchorPoint(Vec2(0.5f, 0.5f));
|
|
|
|
l->setPosition(Vec2( s.width/2, s.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
|
|
|
this->addChild(l, 0, kLayerIgnoreAnchorPoint);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto rot = RotateBy::create(2, 360);
|
2013-06-20 14:17:10 +08:00
|
|
|
l->runAction(RepeatForever::create(rot));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto child = Sprite::create("Images/grossini.png");
|
2012-06-15 15:10:40 +08:00
|
|
|
l->addChild(child);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto lsize = l->getContentSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
child->setPosition(Vec2(lsize.width/2, lsize.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto item = MenuItemFont::create("Toogle ignore anchor point", CC_CALLBACK_1(LayerIgnoreAnchorPointRot::onToggle, this));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto menu = Menu::create(item, nullptr);
|
2012-06-15 15:10:40 +08:00
|
|
|
this->addChild(menu);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
menu->setPosition(Vec2(s.width/2, s.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void LayerIgnoreAnchorPointRot::onToggle(Ref* pObject)
|
2012-06-15 15:10:40 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = this->getChildByTag(kLayerIgnoreAnchorPoint);
|
2013-07-23 08:25:44 +08:00
|
|
|
bool ignore = layer->isIgnoreAnchorPointForPosition();
|
|
|
|
layer->ignoreAnchorPointForPosition(! ignore);
|
2012-06-15 15:10:40 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string LayerIgnoreAnchorPointRot::title() const
|
2012-06-12 15:14:01 +08:00
|
|
|
{
|
|
|
|
return "IgnoreAnchorPoint - Rotation";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string LayerIgnoreAnchorPointRot::subtitle() const
|
2012-06-15 15:10:40 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
return "Ignoring Anchor Vec2 for rotations";
|
2012-06-15 15:10:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// LayerIgnoreAnchorPointScale
|
|
|
|
void LayerIgnoreAnchorPointScale::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto l = LayerColor::create(Color4B(255, 0, 0, 255), 200, 200);
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
l->setAnchorPoint(Vec2(0.5f, 1.0f));
|
|
|
|
l->setPosition(Vec2( s.width/2, s.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scale = ScaleBy::create(2, 2);
|
|
|
|
auto back = (ScaleBy*)scale->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq = Sequence::create(scale, back, nullptr);
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
l->runAction(RepeatForever::create(seq));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
|
|
|
this->addChild(l, 0, kLayerIgnoreAnchorPoint);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto child = Sprite::create("Images/grossini.png");
|
2012-06-15 15:10:40 +08:00
|
|
|
l->addChild(child);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto lsize = l->getContentSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
child->setPosition(Vec2(lsize.width/2, lsize.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto item = MenuItemFont::create("Toogle ignore anchor point", CC_CALLBACK_1(LayerIgnoreAnchorPointScale::onToggle, this));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto menu = Menu::create(item, nullptr);
|
2012-06-15 15:10:40 +08:00
|
|
|
this->addChild(menu);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
menu->setPosition(Vec2(s.width/2, s.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void LayerIgnoreAnchorPointScale::onToggle(Ref* pObject)
|
2012-06-15 15:10:40 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = this->getChildByTag(kLayerIgnoreAnchorPoint);
|
2013-07-23 08:25:44 +08:00
|
|
|
bool ignore = layer->isIgnoreAnchorPointForPosition();
|
|
|
|
layer->ignoreAnchorPointForPosition(! ignore);
|
2012-06-15 15:10:40 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string LayerIgnoreAnchorPointScale::title() const
|
2012-06-12 15:14:01 +08:00
|
|
|
{
|
|
|
|
return "IgnoreAnchorPoint - Scale";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string LayerIgnoreAnchorPointScale::subtitle() const
|
2012-06-15 15:10:40 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
return "Ignoring Anchor Vec2 for scale";
|
2012-06-12 15:14:01 +08:00
|
|
|
}
|
|
|
|
|
2012-11-20 18:00:27 +08:00
|
|
|
LayerExtendedBlendOpacityTest::LayerExtendedBlendOpacityTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer1 = LayerGradient::create(Color4B(255, 0, 0, 255), Color4B(255, 0, 255, 255));
|
2013-07-12 14:30:26 +08:00
|
|
|
layer1->setContentSize(Size(80, 80));
|
2014-05-15 01:07:09 +08:00
|
|
|
layer1->setPosition(Vec2(50,50));
|
2012-11-20 18:00:27 +08:00
|
|
|
addChild(layer1);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer2 = LayerGradient::create(Color4B(0, 0, 0, 127), Color4B(255, 255, 255, 127));
|
2013-07-12 14:30:26 +08:00
|
|
|
layer2->setContentSize(Size(80, 80));
|
2014-05-15 01:07:09 +08:00
|
|
|
layer2->setPosition(Vec2(100,90));
|
2012-11-20 18:00:27 +08:00
|
|
|
addChild(layer2);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer3 = LayerGradient::create();
|
2013-07-12 14:30:26 +08:00
|
|
|
layer3->setContentSize(Size(80, 80));
|
2014-05-15 01:07:09 +08:00
|
|
|
layer3->setPosition(Vec2(150,140));
|
2013-07-05 16:49:22 +08:00
|
|
|
layer3->setStartColor(Color3B(255, 0, 0));
|
|
|
|
layer3->setEndColor(Color3B(255, 0, 255));
|
2012-11-20 18:00:27 +08:00
|
|
|
layer3->setStartOpacity(255);
|
|
|
|
layer3->setEndOpacity(255);
|
2013-07-26 04:36:19 +08:00
|
|
|
layer3->setBlendFunc( BlendFunc::ALPHA_NON_PREMULTIPLIED );
|
2012-11-20 18:00:27 +08:00
|
|
|
addChild(layer3);
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string LayerExtendedBlendOpacityTest::title() const
|
2012-11-20 18:00:27 +08:00
|
|
|
{
|
|
|
|
return "Extended Blend & Opacity";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string LayerExtendedBlendOpacityTest::subtitle() const
|
2012-11-20 18:00:27 +08:00
|
|
|
{
|
|
|
|
return "You should see 3 layers";
|
|
|
|
}
|
|
|
|
|
2013-12-11 15:57:20 +08:00
|
|
|
// LayerBug3162A
|
|
|
|
void LayerBug3162A::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
|
|
|
|
|
|
|
Size size = VisibleRect::getVisibleRect().size;
|
|
|
|
size.width = size.width / 2;
|
|
|
|
size.height = size.height / 3;
|
|
|
|
Color4B color[3] = {Color4B(255, 0, 0, 255), Color4B(0, 255, 0, 255), Color4B(0, 0, 255, 255)};
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
|
{
|
|
|
|
_layer[i] = LayerColor::create(color[i]);
|
|
|
|
_layer[i]->setContentSize(size);
|
2014-05-15 01:07:09 +08:00
|
|
|
_layer[i]->setPosition(Vec2(size.width/2, size.height/2) - Vec2(20, 20));
|
2013-12-11 15:57:20 +08:00
|
|
|
_layer[i]->setOpacity(150);
|
|
|
|
_layer[i]->setCascadeOpacityEnabled(true);
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
_layer[i-1]->addChild(_layer[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this->addChild(_layer[0]);
|
|
|
|
|
2014-10-04 00:38:36 +08:00
|
|
|
schedule(CC_SCHEDULE_SELECTOR(LayerBug3162A::step), 0.5, CC_REPEAT_FOREVER, 0);
|
2013-12-11 15:57:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LayerBug3162A::step(float dt)
|
|
|
|
{
|
|
|
|
_layer[0]->setCascadeOpacityEnabled(!_layer[0]->isCascadeOpacityEnabled());
|
|
|
|
}
|
|
|
|
|
2013-12-20 04:23:42 +08:00
|
|
|
std::string LayerBug3162A::title() const
|
2013-12-11 15:57:20 +08:00
|
|
|
{
|
|
|
|
return "Bug 3162 red layer cascade opacity eable/disable";
|
|
|
|
}
|
|
|
|
|
2013-12-20 04:23:42 +08:00
|
|
|
std::string LayerBug3162A::subtitle() const
|
2013-12-11 15:57:20 +08:00
|
|
|
{
|
|
|
|
return "g and b layer opacity is effected/diseffected with r layer";
|
|
|
|
}
|
|
|
|
|
|
|
|
// LayerBug3162B
|
|
|
|
void LayerBug3162B::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
|
|
|
|
|
|
|
Size size = VisibleRect::getVisibleRect().size;
|
|
|
|
size.width = size.width / 2;
|
|
|
|
size.height = size.height / 3;
|
|
|
|
Color4B color[3] = {Color4B(200, 0, 0, 255), Color4B(150, 0, 0, 255), Color4B(100, 0, 0, 255)};
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
|
{
|
|
|
|
_layer[i] = LayerColor::create(color[i]);
|
|
|
|
_layer[i]->setContentSize(size);
|
2014-05-15 01:07:09 +08:00
|
|
|
_layer[i]->setPosition(Vec2(size.width/2, size.height/2) - Vec2(20, 20));
|
2013-12-11 15:57:20 +08:00
|
|
|
//_layer[i]->setOpacity(150);
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
_layer[i-1]->addChild(_layer[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this->addChild(_layer[0]);
|
|
|
|
|
|
|
|
_layer[0]->setCascadeColorEnabled(true);
|
|
|
|
_layer[1]->setCascadeColorEnabled(true);
|
|
|
|
_layer[2]->setCascadeColorEnabled(true);
|
|
|
|
|
2014-10-04 00:38:36 +08:00
|
|
|
schedule(CC_SCHEDULE_SELECTOR(LayerBug3162B::step), 0.5, CC_REPEAT_FOREVER, 0);
|
2013-12-11 15:57:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LayerBug3162B::step(float dt)
|
|
|
|
{
|
|
|
|
_layer[0]->setCascadeColorEnabled(!_layer[0]->isCascadeColorEnabled());
|
|
|
|
}
|
|
|
|
|
2013-12-20 04:23:42 +08:00
|
|
|
std::string LayerBug3162B::title() const
|
2013-12-11 15:57:20 +08:00
|
|
|
{
|
2013-12-16 04:13:49 +08:00
|
|
|
return "Bug 3162 bottom layer cascade color eable/disable";
|
2013-12-11 15:57:20 +08:00
|
|
|
}
|
|
|
|
|
2013-12-20 04:23:42 +08:00
|
|
|
std::string LayerBug3162B::subtitle() const
|
2013-12-11 15:57:20 +08:00
|
|
|
{
|
2013-12-16 04:13:49 +08:00
|
|
|
return "u and m layer color is effected/diseffected with b layer";
|
2013-12-11 15:57:20 +08:00
|
|
|
}
|
2014-01-09 14:50:29 +08:00
|
|
|
|
|
|
|
std::string LayerColorOccludeBug::title() const
|
|
|
|
{
|
|
|
|
return "Layer Color Occlude Bug Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerColorOccludeBug::subtitle() const
|
|
|
|
{
|
|
|
|
return "Layer Color Should not occlude titles and any sprites";
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerColorOccludeBug::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
|
|
|
Director::getInstance()->setDepthTest(true);
|
|
|
|
_layer = LayerColor::create(Color4B(0, 80, 95, 255));
|
|
|
|
addChild(_layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerColorOccludeBug::onExit()
|
|
|
|
{
|
|
|
|
LayerTest::onExit();
|
|
|
|
Director::getInstance()->setDepthTest(false);
|
|
|
|
}
|