2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
http://www.cocos2d-x.org
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
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:
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
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 "LayerTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
#include "../cocos/ui/UIText.h"
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
enum
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
kTagLayer = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
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(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);
|
|
|
|
ADD_TEST_CASE(LayerRadialGradientTest);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cascading support extensions
|
|
|
|
|
|
|
|
static void setEnableRecursiveCascading(Node* node, bool enable)
|
|
|
|
{
|
|
|
|
node->setCascadeColorEnabled(enable);
|
|
|
|
node->setCascadeOpacityEnabled(enable);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto& children = node->getChildren();
|
2021-12-31 11:00:35 +08:00
|
|
|
for(const auto &child : children) {
|
2019-11-23 20:27:39 +08:00
|
|
|
setEnableRecursiveCascading(child, enable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerTest::title() const
|
|
|
|
{
|
|
|
|
return "Layer Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
// LayerTestCascadingOpacityA
|
|
|
|
void LayerTestCascadingOpacityA::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
2021-12-31 11:00:35 +08:00
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2019-11-23 20:27:39 +08:00
|
|
|
auto layer1 = Layer::create();
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
|
2021-12-31 11:00:35 +08:00
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
2021-12-31 11:00:35 +08:00
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
layer1->runAction(
|
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
FadeTo::create(4, 0),
|
|
|
|
FadeTo::create(4, 255),
|
|
|
|
DelayTime::create(1),
|
|
|
|
nullptr)));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
sister1->runAction(
|
2021-12-31 11:00:35 +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),
|
|
|
|
nullptr)));
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// Enable cascading in scene
|
|
|
|
setEnableRecursiveCascading(this, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerTestCascadingOpacityA::subtitle() const
|
|
|
|
{
|
|
|
|
return "Layer: cascading opacity";
|
|
|
|
}
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// LayerTestCascadingOpacityB
|
|
|
|
void LayerTestCascadingOpacityB::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
2021-12-31 11:00:35 +08:00
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto layer1 = LayerColor::create(Color4B(192, 0, 0, 255), s.width, s.height/2);
|
2019-11-23 20:27:39 +08:00
|
|
|
layer1->setCascadeColorEnabled(false);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
|
|
|
layer1->setPosition( Vec2(0.0f, s.height/2));
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
|
2021-12-31 11:00:35 +08:00
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
2021-12-31 11:00:35 +08:00
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
|
|
|
sister1->setPosition( Vec2( s.width*1/3, 0.0f));
|
|
|
|
sister2->setPosition( Vec2( s.width*2/3, 0.0f));
|
|
|
|
label->setPosition( Vec2( s.width/2, 0.0f));
|
|
|
|
|
|
|
|
layer1->runAction(
|
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
FadeTo::create(4, 0),
|
|
|
|
FadeTo::create(4, 255),
|
|
|
|
DelayTime::create(1),
|
|
|
|
nullptr)));
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
sister1->runAction(
|
2021-12-31 11:00:35 +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),
|
|
|
|
nullptr)));
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// Enable cascading in scene
|
|
|
|
setEnableRecursiveCascading(this, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerTestCascadingOpacityB::subtitle() const
|
|
|
|
{
|
|
|
|
return "CCLayerColor: cascading opacity";
|
|
|
|
}
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// LayerTestCascadingOpacityC
|
|
|
|
void LayerTestCascadingOpacityC::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
2021-12-31 11:00:35 +08:00
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto layer1 = LayerColor::create(Color4B(192, 0, 0, 255), s.width, s.height/2);
|
2019-11-23 20:27:39 +08:00
|
|
|
layer1->setCascadeColorEnabled(false);
|
|
|
|
layer1->setCascadeOpacityEnabled(false);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
|
|
|
layer1->setPosition( Vec2(0.0f, s.height/2));
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
|
2021-12-31 11:00:35 +08:00
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
2021-12-31 11:00:35 +08:00
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
|
|
|
sister1->setPosition( Vec2( s.width*1/3, 0.0f));
|
|
|
|
sister2->setPosition( Vec2( s.width*2/3, 0.0f));
|
|
|
|
label->setPosition( Vec2( s.width/2, 0.0f));
|
|
|
|
|
|
|
|
layer1->runAction(
|
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
FadeTo::create(4, 0),
|
|
|
|
FadeTo::create(4, 255),
|
|
|
|
DelayTime::create(1),
|
|
|
|
nullptr)));
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
sister1->runAction(
|
2021-12-31 11:00:35 +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),
|
|
|
|
nullptr)));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerTestCascadingOpacityC::subtitle() const
|
|
|
|
{
|
|
|
|
return "CCLayerColor: non-cascading opacity";
|
|
|
|
}
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
//// Example LayerTestCascadingColor
|
|
|
|
|
|
|
|
// LayerTestCascadingColorA
|
|
|
|
void LayerTestCascadingColorA::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
2021-12-31 11:00:35 +08:00
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2019-11-23 20:27:39 +08:00
|
|
|
auto layer1 = Layer::create();
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
|
2021-12-31 11:00:35 +08:00
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
2021-12-31 11:00:35 +08:00
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
layer1->runAction(
|
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
TintTo::create(6, 255, 0, 255),
|
|
|
|
TintTo::create(6, 255, 255, 255),
|
|
|
|
DelayTime::create(1),
|
|
|
|
nullptr)));
|
|
|
|
|
|
|
|
sister1->runAction(
|
|
|
|
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),
|
|
|
|
nullptr)));
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// Enable cascading in scene
|
|
|
|
setEnableRecursiveCascading(this, true);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerTestCascadingColorA::subtitle() const
|
|
|
|
{
|
|
|
|
return "Layer: cascading color";
|
|
|
|
}
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// LayerTestCascadingColorB
|
|
|
|
void LayerTestCascadingColorB::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
2021-12-31 11:00:35 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto layer1 = LayerColor::create(Color4B(255, 255, 255, 255), s.width, s.height/2);
|
|
|
|
|
|
|
|
layer1->setPosition( Vec2(0.0f, s.height/2));
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
|
2021-12-31 11:00:35 +08:00
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
2021-12-31 11:00:35 +08:00
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
|
|
|
sister1->setPosition( Vec2( s.width*1/3, 0.0f));
|
|
|
|
sister2->setPosition( Vec2( s.width*2/3, 0.0f));
|
|
|
|
label->setPosition( Vec2( s.width/2, 0.0f));
|
|
|
|
|
|
|
|
layer1->runAction(
|
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
TintTo::create(6, 255, 0, 255),
|
|
|
|
TintTo::create(6, 255, 255, 255),
|
|
|
|
DelayTime::create(1),
|
|
|
|
nullptr)));
|
|
|
|
|
|
|
|
sister1->runAction(
|
|
|
|
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),
|
|
|
|
nullptr)));
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// Enable cascading in scene
|
|
|
|
setEnableRecursiveCascading(this, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerTestCascadingColorB::subtitle() const
|
|
|
|
{
|
|
|
|
return "CCLayerColor: cascading color";
|
|
|
|
}
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// LayerTestCascadingColorC
|
|
|
|
void LayerTestCascadingColorC::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
2021-12-31 11:00:35 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto layer1 = LayerColor::create(Color4B(255, 255, 255, 255), s.width, s.height/2);
|
2019-11-23 20:27:39 +08:00
|
|
|
layer1->setCascadeColorEnabled(false);
|
2021-12-31 11:00:35 +08:00
|
|
|
layer1->setPosition( Vec2(0.0f, s.height/2));
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
auto sister2 = Sprite::create("Images/grossinis_sister2.png");
|
2021-12-31 11:00:35 +08:00
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Test");
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
2021-12-31 11:00:35 +08:00
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
|
|
|
sister1->setPosition( Vec2( s.width*1/3, 0.0f));
|
|
|
|
sister2->setPosition( Vec2( s.width*2/3, 0.0f));
|
|
|
|
label->setPosition( Vec2( s.width/2, 0.0f));
|
|
|
|
|
|
|
|
layer1->runAction(
|
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
|
|
|
TintTo::create(6, 255, 0, 255),
|
|
|
|
TintTo::create(6, 255, 255, 255),
|
|
|
|
DelayTime::create(1),
|
|
|
|
nullptr)));
|
|
|
|
|
|
|
|
sister1->runAction(
|
|
|
|
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),
|
|
|
|
nullptr)));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerTestCascadingColorC::subtitle() const
|
|
|
|
{
|
|
|
|
return "CCLayerColor: non-cascading color";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// LayerTest1
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void LayerTest1::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
2019-11-23 20:27:39 +08:00
|
|
|
listener->onTouchesBegan = CC_CALLBACK_2(LayerTest1::onTouchesBegan, this);
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(LayerTest1::onTouchesMoved, this);
|
|
|
|
listener->onTouchesEnded = CC_CALLBACK_2(LayerTest1::onTouchesEnded, this);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto layer = LayerColor::create( Color4B(0xFF, 0x00, 0x00, 0x80), 200, 200);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
layer->setIgnoreAnchorPointForPosition(false);
|
2021-12-31 11:00:35 +08:00
|
|
|
layer->setPosition( Vec2(s.width/2, s.height/2) );
|
2019-11-23 20:27:39 +08:00
|
|
|
addChild(layer, 1, kTagLayer);
|
|
|
|
}
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
void LayerTest1::updateSize(Vec2 &touchLocation)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2021-12-31 11:00:35 +08:00
|
|
|
|
|
|
|
auto newSize = Size( fabs(touchLocation.x - s.width/2)*2, fabs(touchLocation.y - s.height/2)*2);
|
|
|
|
|
|
|
|
auto l = (LayerColor*) getChildByTag(kTagLayer);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
l->setContentSize( newSize );
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
void LayerTest1::onTouchesBegan(const std::vector<Touch*>& touches, Event *event)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
onTouchesMoved(touches, event);
|
|
|
|
}
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
void LayerTest1::onTouchesMoved(const std::vector<Touch*>& touches, Event *event)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
auto touchLocation = touches[0]->getLocation();
|
|
|
|
|
|
|
|
updateSize(touchLocation);
|
|
|
|
}
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
void LayerTest1::onTouchesEnded(const std::vector<Touch*>& touches, Event *event)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
onTouchesMoved(touches, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerTest1::subtitle() const
|
|
|
|
{
|
|
|
|
return "ColorLayer resize (tap & move)";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// LayerTest2
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void LayerTest2::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto layer1 = LayerColor::create( Color4B(255, 255, 0, 80), 100, 300);
|
|
|
|
layer1->setPosition(Vec2(s.width/3, s.height/2));
|
2019-11-23 20:27:39 +08:00
|
|
|
layer1->setIgnoreAnchorPointForPosition(false);
|
|
|
|
addChild(layer1, 1);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
|
|
|
auto layer2 = LayerColor::create( Color4B(0, 0, 255, 255), 100, 300);
|
|
|
|
layer2->setPosition(Vec2((s.width/3)*2, s.height/2));
|
2019-11-23 20:27:39 +08:00
|
|
|
layer2->setIgnoreAnchorPointForPosition(false);
|
|
|
|
addChild(layer2, 1);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
|
|
|
auto actionTint = TintBy::create(2, -255, -127, 0);
|
2019-11-23 20:27:39 +08:00
|
|
|
auto actionTintBack = actionTint->reverse();
|
2021-12-31 11:00:35 +08:00
|
|
|
auto seq1 = Sequence::create( actionTint, actionTintBack, nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
layer1->runAction(seq1);
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
auto actionFade = FadeOut::create(2.0f);
|
2019-11-23 20:27:39 +08:00
|
|
|
auto actionFadeBack = actionFade->reverse();
|
2021-12-31 11:00:35 +08:00
|
|
|
auto seq2 = Sequence::create(actionFade, actionFadeBack, nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
layer2->runAction(seq2);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerTest2::subtitle() const
|
|
|
|
{
|
|
|
|
return "ColorLayer: fade and tint";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// LayerTestBlend
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
LayerTestBlend::LayerTestBlend()
|
|
|
|
{
|
2021-12-31 11:00:35 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto layer1 = LayerColor::create( Color4B(255, 255, 255, 80) );
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto sister1 = Sprite::create(s_pathSister1);
|
|
|
|
auto sister2 = Sprite::create(s_pathSister2);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
addChild(sister1);
|
|
|
|
addChild(sister2);
|
|
|
|
addChild(layer1, 100, kTagLayer);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
|
|
|
sister1->setPosition( Vec2( s.width*1/3, s.height/2) );
|
|
|
|
sister2->setPosition( Vec2( s.width*2/3, s.height/2) );
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
schedule( CC_SCHEDULE_SELECTOR(LayerTestBlend::newBlend), 1.0f);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LayerTestBlend::newBlend(float dt)
|
|
|
|
{
|
2021-12-31 11:00:35 +08:00
|
|
|
auto layer = (LayerColor*)getChildByTag(kTagLayer);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
backend::BlendFactor src;
|
|
|
|
backend::BlendFactor dst;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
if( layer->getBlendFunc().dst == backend::BlendFactor::ZERO )
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
src = backend::BlendFactor::SRC_ALPHA;
|
|
|
|
dst = backend::BlendFactor::ONE_MINUS_SRC_ALPHA;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
src = backend::BlendFactor::ONE_MINUS_DST_COLOR;
|
|
|
|
dst = backend::BlendFactor::ZERO;
|
|
|
|
}
|
|
|
|
|
|
|
|
BlendFunc bf = {src, dst};
|
2021-12-31 11:00:35 +08:00
|
|
|
layer->setBlendFunc( bf );
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
std::string LayerTestBlend::subtitle() const
|
|
|
|
{
|
|
|
|
return "ColorLayer: blend";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// LayerGradientTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
LayerGradientTest::LayerGradientTest()
|
|
|
|
{
|
2021-12-31 11:00:35 +08:00
|
|
|
auto layer1 = LayerGradient::create(Color4B(255,0,0,255), Color4B(0,255,0,255), Vec2(0.9f, 0.9f));
|
2019-11-23 20:27:39 +08:00
|
|
|
addChild(layer1, 0, kTagLayer);
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
2019-11-23 20:27:39 +08:00
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(LayerGradientTest::onTouchesMoved, this);
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
|
|
|
|
auto label1 = Label::createWithTTF("Compressed Interpolation: Enabled", "fonts/Marker Felt.ttf", 26);
|
|
|
|
auto label2 = Label::createWithTTF("Compressed Interpolation: Disabled", "fonts/Marker Felt.ttf", 26);
|
2021-12-31 11:00:35 +08:00
|
|
|
auto item1 = MenuItemLabel::create(label1);
|
|
|
|
auto item2 = MenuItemLabel::create(label2);
|
|
|
|
auto item = MenuItemToggle::createWithCallback( CC_CALLBACK_1(LayerGradientTest::toggleItem, this), item1, item2, nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
auto menu = Menu::create(item, nullptr);
|
|
|
|
addChild(menu);
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
menu->setPosition(Vec2(s.width / 2, 100.0f));
|
|
|
|
}
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
void LayerGradientTest::toggleItem(Ref *sender)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 11:00:35 +08:00
|
|
|
auto gradient = static_cast<LayerGradient*>( getChildByTag(kTagLayer) );
|
|
|
|
gradient->setCompressedInterpolation(! gradient->isCompressedInterpolation());
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
void LayerGradientTest::onTouchesMoved(const std::vector<Touch*>& touches, Event *event)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto touch = touches[0];
|
2021-12-31 11:00:35 +08:00
|
|
|
auto start = touch->getLocation();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
auto diff = Vec2(s.width/2,s.height/2) - start;
|
|
|
|
diff = diff.getNormalized();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
auto gradient = static_cast<LayerGradient*>( getChildByTag(1) );
|
2019-11-23 20:27:39 +08:00
|
|
|
gradient->setVector(diff);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerGradientTest::title() const
|
|
|
|
{
|
|
|
|
return "LayerGradientTest";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerGradientTest::subtitle() const
|
|
|
|
{
|
|
|
|
return "Touch the screen and move your finger";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// LayerGradientTest2
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
LayerGradientTest2::LayerGradientTest2()
|
|
|
|
{
|
2021-12-31 11:00:35 +08:00
|
|
|
auto layer = LayerGradient::create(Color4B(255,0,0,255), Color4B(255,255,0,255));
|
2019-11-23 20:27:39 +08:00
|
|
|
addChild(layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerGradientTest2::title() const
|
|
|
|
{
|
|
|
|
return "LayerGradientTest 2";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerGradientTest2::subtitle() const
|
|
|
|
{
|
|
|
|
return "You should see a gradient";
|
|
|
|
}
|
|
|
|
|
|
|
|
// LayerIgnoreAnchorPointPos
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
#define kLayerIgnoreAnchorPoint 1000
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
void LayerIgnoreAnchorPointPos::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto l = LayerColor::create(Color4B(255, 0, 0, 255), 150, 150);
|
|
|
|
|
|
|
|
l->setAnchorPoint(Vec2(0.5f, 0.5f));
|
2021-12-31 11:00:35 +08:00
|
|
|
l->setPosition(Vec2( s.width/2, s.height/2));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
auto move = MoveBy::create(2, Vec2(100,2));
|
|
|
|
auto back = (MoveBy *)move->reverse();
|
|
|
|
auto seq = Sequence::create(move, back, nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
l->runAction(RepeatForever::create(seq));
|
|
|
|
this->addChild(l, 0, kLayerIgnoreAnchorPoint);
|
|
|
|
|
|
|
|
auto child = Sprite::create("Images/grossini.png");
|
|
|
|
l->addChild(child);
|
|
|
|
auto lsize = l->getContentSize();
|
2021-12-31 11:00:35 +08:00
|
|
|
child->setPosition(Vec2(lsize.width/2, lsize.height/2));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
auto item = MenuItemFont::create("Toggle ignore anchor point", CC_CALLBACK_1(LayerIgnoreAnchorPointPos::onToggle, this));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
auto menu = Menu::create(item, nullptr);
|
|
|
|
this->addChild(menu);
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
menu->setPosition(Vec2(s.width/2, s.height/2));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LayerIgnoreAnchorPointPos::onToggle(Ref* pObject)
|
|
|
|
{
|
2021-12-31 11:00:35 +08:00
|
|
|
auto layer = this->getChildByTag(kLayerIgnoreAnchorPoint);
|
2019-11-23 20:27:39 +08:00
|
|
|
bool ignore = layer->isIgnoreAnchorPointForPosition();
|
2021-12-31 11:00:35 +08:00
|
|
|
layer->setIgnoreAnchorPointForPosition(! ignore);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerIgnoreAnchorPointPos::title() const
|
|
|
|
{
|
|
|
|
return "IgnoreAnchorPoint - Position";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerIgnoreAnchorPointPos::subtitle() const
|
|
|
|
{
|
|
|
|
return "Ignoring Anchor Vec2 for position";
|
|
|
|
}
|
|
|
|
|
|
|
|
// LayerIgnoreAnchorPointRot
|
|
|
|
|
|
|
|
void LayerIgnoreAnchorPointRot::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto l = LayerColor::create(Color4B(255, 0, 0, 255), 200, 200);
|
|
|
|
|
|
|
|
l->setAnchorPoint(Vec2(0.5f, 0.5f));
|
2021-12-31 11:00:35 +08:00
|
|
|
l->setPosition(Vec2( s.width/2, s.height/2));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
this->addChild(l, 0, kLayerIgnoreAnchorPoint);
|
|
|
|
|
|
|
|
auto rot = RotateBy::create(2, 360);
|
|
|
|
l->runAction(RepeatForever::create(rot));
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto child = Sprite::create("Images/grossini.png");
|
|
|
|
l->addChild(child);
|
|
|
|
auto lsize = l->getContentSize();
|
2021-12-31 11:00:35 +08:00
|
|
|
child->setPosition(Vec2(lsize.width/2, lsize.height/2));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
auto item = MenuItemFont::create("Toggle ignore anchor point", CC_CALLBACK_1(LayerIgnoreAnchorPointRot::onToggle, this));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
auto menu = Menu::create(item, nullptr);
|
|
|
|
this->addChild(menu);
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
menu->setPosition(Vec2(s.width/2, s.height/2));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LayerIgnoreAnchorPointRot::onToggle(Ref* pObject)
|
|
|
|
{
|
2021-12-31 11:00:35 +08:00
|
|
|
auto layer = this->getChildByTag(kLayerIgnoreAnchorPoint);
|
2019-11-23 20:27:39 +08:00
|
|
|
bool ignore = layer->isIgnoreAnchorPointForPosition();
|
2021-12-31 11:00:35 +08:00
|
|
|
layer->setIgnoreAnchorPointForPosition(! ignore);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerIgnoreAnchorPointRot::title() const
|
|
|
|
{
|
|
|
|
return "IgnoreAnchorPoint - Rotation";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerIgnoreAnchorPointRot::subtitle() const
|
|
|
|
{
|
|
|
|
return "Ignoring Anchor Vec2 for rotations";
|
|
|
|
}
|
|
|
|
|
|
|
|
// LayerIgnoreAnchorPointScale
|
|
|
|
void LayerIgnoreAnchorPointScale::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto l = LayerColor::create(Color4B(255, 0, 0, 255), 200, 200);
|
|
|
|
|
|
|
|
l->setAnchorPoint(Vec2(0.5f, 1.0f));
|
2021-12-31 11:00:35 +08:00
|
|
|
l->setPosition(Vec2( s.width/2, s.height/2));
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
auto scale = ScaleBy::create(2, 2);
|
2021-12-31 11:00:35 +08:00
|
|
|
auto back = (ScaleBy*)scale->reverse();
|
|
|
|
auto seq = Sequence::create(scale, back, nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
l->runAction(RepeatForever::create(seq));
|
|
|
|
|
|
|
|
this->addChild(l, 0, kLayerIgnoreAnchorPoint);
|
|
|
|
|
|
|
|
auto child = Sprite::create("Images/grossini.png");
|
|
|
|
l->addChild(child);
|
|
|
|
auto lsize = l->getContentSize();
|
2021-12-31 11:00:35 +08:00
|
|
|
child->setPosition(Vec2(lsize.width/2, lsize.height/2));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
auto item = MenuItemFont::create("Toggle ignore anchor point", CC_CALLBACK_1(LayerIgnoreAnchorPointScale::onToggle, this));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
auto menu = Menu::create(item, nullptr);
|
|
|
|
this->addChild(menu);
|
|
|
|
|
2021-12-31 11:00:35 +08:00
|
|
|
menu->setPosition(Vec2(s.width/2, s.height/2));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LayerIgnoreAnchorPointScale::onToggle(Ref* pObject)
|
|
|
|
{
|
2021-12-31 11:00:35 +08:00
|
|
|
auto layer = this->getChildByTag(kLayerIgnoreAnchorPoint);
|
2019-11-23 20:27:39 +08:00
|
|
|
bool ignore = layer->isIgnoreAnchorPointForPosition();
|
2021-12-31 11:00:35 +08:00
|
|
|
layer->setIgnoreAnchorPointForPosition(! ignore);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerIgnoreAnchorPointScale::title() const
|
|
|
|
{
|
|
|
|
return "IgnoreAnchorPoint - Scale";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerIgnoreAnchorPointScale::subtitle() const
|
|
|
|
{
|
|
|
|
return "Ignoring Anchor Vec2 for scale";
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerExtendedBlendOpacityTest::LayerExtendedBlendOpacityTest()
|
|
|
|
{
|
|
|
|
auto layer1 = LayerGradient::create(Color4B(255, 0, 0, 255), Color4B(255, 0, 255, 255));
|
|
|
|
layer1->setContentSize(Size(80.0f, 80.0f));
|
2021-12-31 11:00:35 +08:00
|
|
|
layer1->setPosition(Vec2(50.0f,50.0f));
|
2019-11-23 20:27:39 +08:00
|
|
|
addChild(layer1);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto layer2 = LayerGradient::create(Color4B(0, 0, 0, 127), Color4B(255, 255, 255, 127));
|
|
|
|
layer2->setContentSize(Size(80.0f, 80.0f));
|
2021-12-31 11:00:35 +08:00
|
|
|
layer2->setPosition(Vec2(100.0f,90.0f));
|
2019-11-23 20:27:39 +08:00
|
|
|
addChild(layer2);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto layer3 = LayerGradient::create();
|
|
|
|
layer3->setContentSize(Size(80.0f, 80.0f));
|
2021-12-31 11:00:35 +08:00
|
|
|
layer3->setPosition(Vec2(150.0f,140.0f));
|
2019-11-23 20:27:39 +08:00
|
|
|
layer3->setStartColor(Color3B(255, 0, 0));
|
|
|
|
layer3->setEndColor(Color3B(255, 0, 255));
|
|
|
|
layer3->setStartOpacity(255);
|
|
|
|
layer3->setEndOpacity(255);
|
2021-12-31 11:00:35 +08:00
|
|
|
layer3->setBlendFunc( BlendFunc::ALPHA_NON_PREMULTIPLIED );
|
2019-11-23 20:27:39 +08:00
|
|
|
addChild(layer3);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerExtendedBlendOpacityTest::title() const
|
|
|
|
{
|
|
|
|
return "Extended Blend & Opacity";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerExtendedBlendOpacityTest::subtitle() const
|
|
|
|
{
|
|
|
|
return "You should see 3 layers";
|
|
|
|
}
|
|
|
|
|
|
|
|
// LayerBug3162A
|
|
|
|
void LayerBug3162A::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
2021-12-31 11:00:35 +08:00
|
|
|
|
|
|
|
Size size = VisibleRect::getVisibleRect().size;
|
|
|
|
size.width = size.width / 2;
|
|
|
|
size.height = size.height / 3;
|
2019-11-23 20:27:39 +08:00
|
|
|
Color4B color[3] = {Color4B(255, 0, 0, 255), Color4B(0, 255, 0, 255), Color4B(0, 0, 255, 255)};
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
|
{
|
|
|
|
_layer[i] = LayerColor::create(color[i]);
|
|
|
|
_layer[i]->setContentSize(size);
|
2021-12-31 11:00:35 +08:00
|
|
|
_layer[i]->setPosition(Vec2(size.width/2, size.height/2) - Vec2(20.0f, 20.0f));
|
2019-11-23 20:27:39 +08:00
|
|
|
_layer[i]->setOpacity(150);
|
|
|
|
_layer[i]->setCascadeOpacityEnabled(true);
|
|
|
|
if (i > 0)
|
|
|
|
{
|
2021-12-31 11:00:35 +08:00
|
|
|
_layer[i-1]->addChild(_layer[i]);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
this->addChild(_layer[0]);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
schedule(CC_SCHEDULE_SELECTOR(LayerBug3162A::step), 0.5, CC_REPEAT_FOREVER, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerBug3162A::step(float dt)
|
|
|
|
{
|
|
|
|
_layer[0]->setCascadeOpacityEnabled(!_layer[0]->isCascadeOpacityEnabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerBug3162A::title() const
|
|
|
|
{
|
|
|
|
return "Bug 3162 red layer cascade opacity enable/disable";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerBug3162A::subtitle() const
|
|
|
|
{
|
|
|
|
return "g and b layer opacity is effected/diseffected with r layer";
|
|
|
|
}
|
|
|
|
|
|
|
|
// LayerBug3162B
|
|
|
|
void LayerBug3162B::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
2021-12-31 11:00:35 +08:00
|
|
|
|
|
|
|
Size size = VisibleRect::getVisibleRect().size;
|
|
|
|
size.width = size.width / 2;
|
|
|
|
size.height = size.height / 3;
|
2019-11-23 20:27:39 +08:00
|
|
|
Color4B color[3] = {Color4B(200, 0, 0, 255), Color4B(150, 0, 0, 255), Color4B(100, 0, 0, 255)};
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
|
{
|
|
|
|
_layer[i] = LayerColor::create(color[i]);
|
|
|
|
_layer[i]->setContentSize(size);
|
2021-12-31 11:00:35 +08:00
|
|
|
_layer[i]->setPosition(Vec2(size.width/2, size.height/2) - Vec2(20.0f, 20.0f));
|
2019-11-23 20:27:39 +08:00
|
|
|
//_layer[i]->setOpacity(150);
|
|
|
|
if (i > 0)
|
|
|
|
{
|
2021-12-31 11:00:35 +08:00
|
|
|
_layer[i-1]->addChild(_layer[i]);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
this->addChild(_layer[0]);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
_layer[0]->setCascadeColorEnabled(true);
|
|
|
|
_layer[1]->setCascadeColorEnabled(true);
|
|
|
|
_layer[2]->setCascadeColorEnabled(true);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
schedule(CC_SCHEDULE_SELECTOR(LayerBug3162B::step), 0.5, CC_REPEAT_FOREVER, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerBug3162B::step(float dt)
|
|
|
|
{
|
|
|
|
_layer[0]->setCascadeColorEnabled(!_layer[0]->isCascadeColorEnabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerBug3162B::title() const
|
|
|
|
{
|
|
|
|
return "Bug 3162 bottom layer cascade color enable/disable";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerBug3162B::subtitle() const
|
|
|
|
{
|
|
|
|
return "u and m layer color is effected/diseffected with b layer";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerColorOccludeBug::title() const
|
|
|
|
{
|
|
|
|
return "Layer Color Occlude Bug Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerColorOccludeBug::subtitle() const
|
|
|
|
{
|
2021-12-31 11:00:35 +08:00
|
|
|
return "Layer Color Should not occlude titles and any sprites";
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LayerColorOccludeBug::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
|
|
|
Director::getInstance()->getRenderer()->setDepthTest(true);
|
|
|
|
_layer = LayerColor::create(Color4B(0, 80, 95, 255));
|
|
|
|
addChild(_layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerColorOccludeBug::onExit()
|
|
|
|
{
|
|
|
|
LayerTest::onExit();
|
|
|
|
Director::getInstance()->getRenderer()->setDepthTest(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// LayerRadialGradient
|
|
|
|
|
|
|
|
std::string LayerRadialGradientTest::title() const
|
|
|
|
{
|
|
|
|
return "LayerRadialGradient test";
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerRadialGradientTest::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
_currentSeletedItemIndex = 0;
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto director = Director::getInstance();
|
|
|
|
director->setClearColor(Color4F(0, 0, 0, 0));
|
|
|
|
auto origin = director->getVisibleOrigin();
|
2021-12-31 11:00:35 +08:00
|
|
|
auto size = director->getVisibleSize();
|
|
|
|
Vec2 center(origin.x + size.width/2 + 50, origin.y + size.height/2);
|
2019-11-23 20:27:39 +08:00
|
|
|
float radius = (size.height - 50) / 2;
|
2021-12-31 11:00:35 +08:00
|
|
|
_layer = LayerRadialGradient::create(Color4B(145, 106, 209, 140), Color4B(0, 0, 0, 0), radius, center, 1.0f);
|
2019-11-23 20:27:39 +08:00
|
|
|
addChild(_layer);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto scaleSlider = LayerRadialGradientTest::createSlider();
|
|
|
|
scaleSlider->setPosition(Vec2(50.0f, 130.0f));
|
|
|
|
addChild(scaleSlider);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto listview = createListView();
|
|
|
|
listview->setPosition(Vec2(100.0f, 150.0f));
|
|
|
|
addChild(listview);
|
|
|
|
}
|
|
|
|
|
|
|
|
cocos2d::ui::Slider* LayerRadialGradientTest::createSlider()
|
|
|
|
{
|
|
|
|
auto slider = ui::Slider::create();
|
|
|
|
slider->setTouchEnabled(true);
|
|
|
|
slider->loadBarTexture("cocosui/sliderTrack.png");
|
|
|
|
slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
|
|
|
|
slider->loadProgressBarTexture("cocosui/sliderProgress.png");
|
|
|
|
slider->addEventListener(CC_CALLBACK_2(LayerRadialGradientTest::sliderCallback, this));
|
|
|
|
slider->setRotation(90);
|
|
|
|
slider->setTag(101);
|
|
|
|
slider->setPercent(50);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
return slider;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerRadialGradientTest::listviewCallback(cocos2d::Ref* sender, cocos2d::ui::ListView::EventType type)
|
|
|
|
{
|
|
|
|
// clear all text to white
|
|
|
|
auto listview = static_cast<cocos2d::ui::ListView*>(sender);
|
2021-12-31 11:00:35 +08:00
|
|
|
for (auto &item : listview->getItems())
|
2019-11-23 20:27:39 +08:00
|
|
|
static_cast<cocos2d::ui::Text*>(item)->setColor(cocos2d::Color3B::WHITE);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
_currentSeletedItemIndex = (int)listview->getCurSelectedIndex();
|
|
|
|
listview->getItem(_currentSeletedItemIndex)->setColor(cocos2d::Color3B::RED);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
int percent = 100;
|
|
|
|
auto slider = static_cast<cocos2d::ui::Slider*>(getChildByTag(101));
|
|
|
|
switch (_currentSeletedItemIndex)
|
|
|
|
{
|
2021-12-31 11:00:35 +08:00
|
|
|
case 0:
|
|
|
|
// scale
|
|
|
|
slider->setPercent(_layer->getScaleX() / 2 * percent);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
// skewx
|
|
|
|
slider->setPercent(_layer->getSkewX() / 90 * percent);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
// skewy
|
|
|
|
slider->setPercent(_layer->getSkewY() / 90 * percent);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
// expand
|
|
|
|
slider->setPercent(_layer->getExpand() * percent);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
// radius
|
|
|
|
slider->setPercent(_layer->getRadius() / 300 * percent);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerRadialGradientTest::sliderCallback(cocos2d::Ref* sender, cocos2d::ui::Slider::EventType type)
|
|
|
|
{
|
2021-12-31 11:00:35 +08:00
|
|
|
auto slider = static_cast<cocos2d::ui::Slider*>(sender);
|
2019-11-23 20:27:39 +08:00
|
|
|
float percent = slider->getPercent() / 100.f;
|
|
|
|
switch (_currentSeletedItemIndex)
|
|
|
|
{
|
2021-12-31 11:00:35 +08:00
|
|
|
case 0:
|
|
|
|
// scale
|
|
|
|
_layer->setScale(percent * 2);
|
|
|
|
CCLOG("scale is %f", percent * 2);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
// skewx
|
|
|
|
_layer->setSkewX(90 * percent);
|
|
|
|
CCLOG("SkewX is %f", 90 * percent);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
// skewy
|
|
|
|
_layer->setSkewY(90 * percent);
|
|
|
|
CCLOG("SkewY is %f", 90 * percent);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
// expand
|
|
|
|
_layer->setExpand(percent);
|
|
|
|
CCLOG("expand is %f", percent);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
// radius
|
|
|
|
_layer->setRadius(300 * percent);
|
|
|
|
CCLOG("radius is %f", 300 * percent);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cocos2d::ui::ListView* LayerRadialGradientTest::createListView()
|
|
|
|
{
|
|
|
|
auto listview = cocos2d::ui::ListView::create();
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto scale = cocos2d::ui::Text::create();
|
|
|
|
scale->setString("scale[0-2]");
|
2021-12-31 11:00:35 +08:00
|
|
|
scale->setColor(cocos2d::Color3B::RED); // default seleted item
|
2019-11-23 20:27:39 +08:00
|
|
|
scale->setTouchEnabled(true);
|
|
|
|
listview->pushBackCustomItem(scale);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto skewx = cocos2d::ui::Text::create();
|
|
|
|
skewx->setString("skewx[0-90]");
|
|
|
|
skewx->setTouchEnabled(true);
|
|
|
|
listview->pushBackCustomItem(skewx);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto skewy = cocos2d::ui::Text::create();
|
|
|
|
skewy->setString("skewy[0-90]");
|
|
|
|
skewy->setTouchEnabled(true);
|
|
|
|
listview->pushBackCustomItem(skewy);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto expand = cocos2d::ui::Text::create();
|
|
|
|
expand->setString("expand[0-1]");
|
|
|
|
expand->setTouchEnabled(true);
|
|
|
|
listview->pushBackCustomItem(expand);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto radius = cocos2d::ui::Text::create();
|
|
|
|
radius->setString("radius[0-300]");
|
|
|
|
radius->setTouchEnabled(true);
|
|
|
|
listview->pushBackCustomItem(radius);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
listview->setContentSize(scale->getContentSize() * 5);
|
|
|
|
listview->setCurSelectedIndex(0);
|
|
|
|
listview->setTouchEnabled(true);
|
2021-12-31 11:00:35 +08:00
|
|
|
listview->addEventListener((ui::ListView::ccListViewCallback)CC_CALLBACK_2(LayerRadialGradientTest::listviewCallback, this));
|
2019-11-23 20:27:39 +08:00
|
|
|
listview->setTag(100);
|
2021-12-31 11:00:35 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
return listview;
|
|
|
|
}
|