2010-11-18 14:50:28 +08:00
|
|
|
#include "LayerTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
static std::function<Layer*()> createFunctions[] = {
|
2013-06-08 08:21:11 +08:00
|
|
|
CL(LayerTestCascadingOpacityA),
|
|
|
|
CL(LayerTestCascadingOpacityB),
|
|
|
|
CL(LayerTestCascadingOpacityC),
|
|
|
|
CL(LayerTestCascadingColorA),
|
|
|
|
CL(LayerTestCascadingColorB),
|
|
|
|
CL(LayerTestCascadingColorC),
|
|
|
|
CL(LayerTest1),
|
|
|
|
CL(LayerTest2),
|
|
|
|
CL(LayerTestBlend),
|
2013-06-29 10:02:10 +08:00
|
|
|
CL(LayerGradientTest),
|
|
|
|
CL(LayerGradientTest2),
|
|
|
|
CL(LayerGradientTest3),
|
2013-06-08 08:21:11 +08:00
|
|
|
CL(LayerIgnoreAnchorPointPos),
|
|
|
|
CL(LayerIgnoreAnchorPointRot),
|
|
|
|
CL(LayerIgnoreAnchorPointScale),
|
|
|
|
CL(LayerExtendedBlendOpacityTest)
|
2013-02-28 16:03:55 +08:00
|
|
|
};
|
2010-08-31 17:03:58 +08:00
|
|
|
|
2013-02-28 16:03:55 +08:00
|
|
|
static int sceneIdx=-1;
|
|
|
|
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
2010-08-31 17:03:58 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
static Layer* nextAction()
|
2010-08-31 17:03:58 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx++;
|
|
|
|
sceneIdx = sceneIdx % MAX_LAYER;
|
2013-02-28 16:03:55 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* pLayer = (createFunctions[sceneIdx])();
|
2012-04-19 14:35:52 +08:00
|
|
|
pLayer->autorelease();
|
2013-02-28 16:03:55 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return pLayer;
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
static Layer* backAction()
|
2010-08-31 17:03:58 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx--;
|
|
|
|
int total = MAX_LAYER;
|
|
|
|
if( sceneIdx < 0 )
|
2013-02-28 16:03:55 +08:00
|
|
|
sceneIdx += total;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* pLayer = (createFunctions[sceneIdx])();
|
2012-04-19 14:35:52 +08:00
|
|
|
pLayer->autorelease();
|
2013-02-28 16:03:55 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return pLayer;
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
static Layer* restartAction()
|
2010-08-31 17:03:58 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* pLayer = (createFunctions[sceneIdx])();
|
2012-04-19 14:35:52 +08:00
|
|
|
pLayer->autorelease();
|
2013-02-28 16:03:55 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return pLayer;
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2010-08-31 17:03:58 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// LayerTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
|
|
|
|
LayerTest::LayerTest(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerTest::~LayerTest(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-07-06 14:56:05 +08:00
|
|
|
string LayerTest::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "";
|
2011-07-06 14:56:05 +08:00
|
|
|
}
|
|
|
|
|
2010-08-31 17:03:58 +08:00
|
|
|
std::string LayerTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "No title";
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LayerTest::onEnter()
|
|
|
|
{
|
2013-06-07 08:12:28 +08:00
|
|
|
BaseTest::onEnter();
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void LayerTest::restartCallback(Object* pSender)
|
2010-08-31 17:03:58 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene* s = new LayerTestScene();
|
2013-02-28 16:03:55 +08:00
|
|
|
s->addChild(restartAction());
|
2010-08-31 17:03:58 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2010-09-13 17:19:49 +08:00
|
|
|
s->release();
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void LayerTest::nextCallback(Object* pSender)
|
2010-08-31 17:03:58 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene* s = new LayerTestScene();
|
2013-02-28 16:03:55 +08:00
|
|
|
s->addChild( nextAction() );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2010-09-13 17:19:49 +08:00
|
|
|
s->release();
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void LayerTest::backCallback(Object* pSender)
|
2010-08-31 17:03:58 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene* s = new LayerTestScene();
|
2013-02-28 16:03:55 +08:00
|
|
|
s->addChild( backAction() );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2010-09-13 17:19:49 +08:00
|
|
|
s->release();
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
2013-02-28 16:45:59 +08:00
|
|
|
//#pragma mark - 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-06-20 14:17:10 +08:00
|
|
|
RGBAProtocol* rgba = dynamic_cast<RGBAProtocol*>(node);
|
2013-02-28 16:45:59 +08:00
|
|
|
if (rgba)
|
|
|
|
{
|
|
|
|
rgba->setCascadeColorEnabled(enable);
|
|
|
|
rgba->setCascadeOpacityEnabled(enable);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Object* obj;
|
|
|
|
Array* children = node->getChildren();
|
2013-02-28 16:45:59 +08:00
|
|
|
CCARRAY_FOREACH(children, obj)
|
|
|
|
{
|
2013-07-09 14:29:51 +08:00
|
|
|
Node* child = static_cast<Node*>(obj);
|
2013-02-28 16:45:59 +08:00
|
|
|
setEnableRecursiveCascading(child, enable);
|
2013-02-28 16:06:07 +08:00
|
|
|
}
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
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-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2013-06-20 14:17:10 +08:00
|
|
|
LayerRGBA* layer1 = LayerRGBA::create();
|
2013-02-28 16:45:59 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite *sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
Sprite *sister2 = Sprite::create("Images/grossinis_sister2.png");
|
|
|
|
LabelBMFont *label = LabelBMFont::create("Test", "fonts/bitmapFontTest.fnt");
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
sister1->setPosition( Point( s.width*1/3, s.height/2));
|
|
|
|
sister2->setPosition( Point( s.width*2/3, s.height/2));
|
|
|
|
label->setPosition( Point( 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(
|
|
|
|
FadeTo::create(4, 0),
|
|
|
|
FadeTo::create(4, 255),
|
|
|
|
DelayTime::create(1),
|
2013-02-28 16:45:59 +08:00
|
|
|
NULL)));
|
|
|
|
|
|
|
|
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),
|
2013-02-28 16:45:59 +08:00
|
|
|
NULL)));
|
|
|
|
|
|
|
|
|
|
|
|
// Enable cascading in scene
|
|
|
|
setEnableRecursiveCascading(this, true);
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2013-02-28 16:45:59 +08:00
|
|
|
std::string LayerTestCascadingOpacityA::title()
|
2013-02-28 16:03:55 +08:00
|
|
|
{
|
2013-02-28 16:45:59 +08:00
|
|
|
return "LayerRGBA: 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-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2013-07-05 16:49:22 +08:00
|
|
|
LayerColor* layer1 = LayerColor::create(Color4B(192, 0, 0, 255), s.width, s.height/2);
|
2013-02-28 16:45:59 +08:00
|
|
|
layer1->setCascadeColorEnabled(false);
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
layer1->setPosition( Point(0, s.height/2));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite *sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
Sprite *sister2 = Sprite::create("Images/grossinis_sister2.png");
|
|
|
|
LabelBMFont *label = LabelBMFont::create("Test", "fonts/bitmapFontTest.fnt");
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
sister1->setPosition( Point( s.width*1/3, 0));
|
|
|
|
sister2->setPosition( Point( s.width*2/3, 0));
|
|
|
|
label->setPosition( Point( 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),
|
2013-02-28 16:45:59 +08:00
|
|
|
NULL)));
|
|
|
|
|
|
|
|
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),
|
2013-02-28 16:45:59 +08:00
|
|
|
NULL)));
|
|
|
|
|
|
|
|
// Enable cascading in scene
|
|
|
|
setEnableRecursiveCascading(this, true);
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2013-02-28 16:45:59 +08:00
|
|
|
std::string LayerTestCascadingOpacityB::title()
|
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-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2013-07-05 16:49:22 +08:00
|
|
|
LayerColor* 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);
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
layer1->setPosition( Point(0, s.height/2));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite *sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
Sprite *sister2 = Sprite::create("Images/grossinis_sister2.png");
|
|
|
|
LabelBMFont *label = LabelBMFont::create("Test", "fonts/bitmapFontTest.fnt");
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
sister1->setPosition( Point( s.width*1/3, 0));
|
|
|
|
sister2->setPosition( Point( s.width*2/3, 0));
|
|
|
|
label->setPosition( Point( 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),
|
2013-02-28 16:45:59 +08:00
|
|
|
NULL)));
|
|
|
|
|
|
|
|
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),
|
2013-02-28 16:45:59 +08:00
|
|
|
NULL)));
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2013-02-28 16:45:59 +08:00
|
|
|
std::string LayerTestCascadingOpacityC::title()
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-28 16:45:59 +08:00
|
|
|
//#pragma mark Example LayerTestCascadingColor
|
|
|
|
|
|
|
|
// LayerTestCascadingColorA
|
|
|
|
void LayerTestCascadingColorA::onEnter()
|
2013-02-28 16:03:55 +08:00
|
|
|
{
|
2013-02-28 16:45:59 +08:00
|
|
|
LayerTest::onEnter();
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2013-06-20 14:17:10 +08:00
|
|
|
LayerRGBA* layer1 = LayerRGBA::create();
|
2013-02-28 16:45:59 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite *sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
Sprite *sister2 = Sprite::create("Images/grossinis_sister2.png");
|
|
|
|
LabelBMFont *label = LabelBMFont::create("Test", "fonts/bitmapFontTest.fnt");
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
sister1->setPosition( Point( s.width*1/3, s.height/2));
|
|
|
|
sister2->setPosition( Point( s.width*2/3, s.height/2));
|
|
|
|
label->setPosition( Point( 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),
|
2013-02-28 16:45:59 +08:00
|
|
|
NULL)));
|
|
|
|
|
|
|
|
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),
|
2013-02-28 16:45:59 +08:00
|
|
|
NULL)));
|
|
|
|
|
|
|
|
// Enable cascading in scene
|
|
|
|
setEnableRecursiveCascading(this, true);
|
|
|
|
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2013-02-28 16:45:59 +08:00
|
|
|
std::string LayerTestCascadingColorA::title()
|
2013-02-28 16:03:55 +08:00
|
|
|
{
|
2013-02-28 16:45:59 +08:00
|
|
|
return "LayerRGBA: 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-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2013-07-05 16:49:22 +08:00
|
|
|
LayerColor* layer1 = LayerColor::create(Color4B(255, 255, 255, 255), s.width, s.height/2);
|
2013-02-28 16:45:59 +08:00
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
layer1->setPosition( Point(0, s.height/2));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite *sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
Sprite *sister2 = Sprite::create("Images/grossinis_sister2.png");
|
|
|
|
LabelBMFont *label = LabelBMFont::create("Test", "fonts/bitmapFontTest.fnt");
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
sister1->setPosition( Point( s.width*1/3, 0));
|
|
|
|
sister2->setPosition( Point( s.width*2/3, 0));
|
|
|
|
label->setPosition( Point( 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),
|
2013-02-28 16:45:59 +08:00
|
|
|
NULL)));
|
|
|
|
|
|
|
|
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),
|
2013-02-28 16:45:59 +08:00
|
|
|
NULL)));
|
|
|
|
|
|
|
|
// Enable cascading in scene
|
|
|
|
setEnableRecursiveCascading(this, true);
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2013-02-28 16:45:59 +08:00
|
|
|
std::string LayerTestCascadingColorB::title()
|
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-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2013-07-05 16:49:22 +08:00
|
|
|
LayerColor* layer1 = LayerColor::create(Color4B(255, 255, 255, 255), s.width, s.height/2);
|
2013-02-28 16:45:59 +08:00
|
|
|
layer1->setCascadeColorEnabled(false);
|
2013-07-12 14:11:55 +08:00
|
|
|
layer1->setPosition( Point(0, s.height/2));
|
2013-02-28 16:45:59 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite *sister1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
Sprite *sister2 = Sprite::create("Images/grossinis_sister2.png");
|
|
|
|
LabelBMFont *label = LabelBMFont::create("Test", "fonts/bitmapFontTest.fnt");
|
2013-02-28 16:45:59 +08:00
|
|
|
|
|
|
|
layer1->addChild(sister1);
|
|
|
|
layer1->addChild(sister2);
|
|
|
|
layer1->addChild(label);
|
|
|
|
this->addChild( layer1, 0, kTagLayer);
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
sister1->setPosition( Point( s.width*1/3, 0));
|
|
|
|
sister2->setPosition( Point( s.width*2/3, 0));
|
|
|
|
label->setPosition( Point( 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),
|
2013-02-28 16:45:59 +08:00
|
|
|
NULL)));
|
|
|
|
|
|
|
|
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),
|
2013-02-28 16:45:59 +08:00
|
|
|
NULL)));
|
2013-02-28 16:03:55 +08:00
|
|
|
}
|
|
|
|
|
2013-02-28 16:45:59 +08:00
|
|
|
std::string LayerTestCascadingColorC::title()
|
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();
|
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
setTouchEnabled(true);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2013-07-05 16:49:22 +08:00
|
|
|
LayerColor* 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);
|
2013-07-12 14:11:55 +08:00
|
|
|
layer->setPosition( Point(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
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void LayerTest1::updateSize(Point &touchLocation)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-12 14:30:26 +08:00
|
|
|
Size 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-06-20 14:17:10 +08:00
|
|
|
LayerColor* l = (LayerColor*) getChildByTag(kTagLayer);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
l->setContentSize( newSize );
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void LayerTest1::ccTouchesBegan(Set *pTouches, Event *pEvent)
|
2010-08-31 17:03:58 +08:00
|
|
|
{
|
2012-11-20 18:00:27 +08:00
|
|
|
ccTouchesMoved(pTouches, pEvent);
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void LayerTest1::ccTouchesMoved(Set *pTouches, Event *pEvent)
|
2010-08-31 17:03:58 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Touch *touch = (Touch*)pTouches->anyObject();
|
|
|
|
Point touchLocation = touch->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-06-20 14:17:10 +08:00
|
|
|
void LayerTest1::ccTouchesEnded(Set *pTouches, Event *pEvent)
|
2010-08-31 17:03:58 +08:00
|
|
|
{
|
2012-11-20 18:00:27 +08:00
|
|
|
ccTouchesMoved(pTouches, pEvent);
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerTest1::title()
|
|
|
|
{
|
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-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2013-07-05 16:49:22 +08:00
|
|
|
LayerColor* layer1 = LayerColor::create( Color4B(255, 255, 0, 80), 100, 300);
|
2013-07-12 14:11:55 +08:00
|
|
|
layer1->setPosition(Point(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-07-05 16:49:22 +08:00
|
|
|
LayerColor* layer2 = LayerColor::create( Color4B(0, 0, 255, 255), 100, 300);
|
2013-07-12 14:11:55 +08:00
|
|
|
layer2->setPosition(Point((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-06-20 14:17:10 +08:00
|
|
|
ActionInterval* actionTint = TintBy::create(2, -255, -127, 0);
|
|
|
|
ActionInterval* actionTintBack = actionTint->reverse();
|
|
|
|
ActionInterval* seq1 = Sequence::create( actionTint, actionTintBack, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
layer1->runAction(seq1);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
ActionInterval* actionFade = FadeOut::create(2.0f);
|
|
|
|
ActionInterval* actionFadeBack = actionFade->reverse();
|
|
|
|
ActionInterval* seq2 = Sequence::create(actionFade, actionFadeBack, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
layer2->runAction(seq2);
|
2010-08-31 17:03:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerTest2::title()
|
|
|
|
{
|
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-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2013-07-05 16:49:22 +08:00
|
|
|
LayerColor* layer1 = LayerColor::create( Color4B(255, 255, 255, 80) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* sister1 = Sprite::create(s_pPathSister1);
|
|
|
|
Sprite* sister2 = Sprite::create(s_pPathSister2);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
addChild(sister1);
|
|
|
|
addChild(sister2);
|
|
|
|
addChild(layer1, 100, kTagLayer);
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
sister1->setPosition( Point( s.width*1/3, s.height/2) );
|
|
|
|
sister2->setPosition( Point( s.width*2/3, s.height/2) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
schedule( 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-06-20 14:17:10 +08:00
|
|
|
LayerColor *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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string LayerTestBlend::title()
|
|
|
|
{
|
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
|
|
|
{
|
2013-07-12 14:11:55 +08:00
|
|
|
LayerGradient* layer1 = LayerGradient::create(Color4B(255,0,0,255), Color4B(0,255,0,255), Point(0.9f, 0.9f));
|
2012-04-08 14:16:29 +08:00
|
|
|
addChild(layer1, 0, kTagLayer);
|
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
setTouchEnabled(true);
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF *label1 = LabelTTF::create("Compressed Interpolation: Enabled", "Marker Felt", 26);
|
|
|
|
LabelTTF *label2 = LabelTTF::create("Compressed Interpolation: Disabled", "Marker Felt", 26);
|
|
|
|
MenuItemLabel *item1 = MenuItemLabel::create(label1);
|
|
|
|
MenuItemLabel *item2 = MenuItemLabel::create(label2);
|
|
|
|
MenuItemToggle *item = MenuItemToggle::createWithCallback( CC_CALLBACK_1(LayerGradientTest::toggleItem, this), item1, item2, NULL);
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menu = Menu::create(item, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(menu);
|
2013-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2013-07-12 14:11:55 +08:00
|
|
|
menu->setPosition(Point(s.width / 2, 100));
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void LayerGradientTest::toggleItem(Object *sender)
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
LayerGradient *gradient = (LayerGradient*)getChildByTag(kTagLayer);
|
2012-06-15 16:47:30 +08:00
|
|
|
gradient->setCompressedInterpolation(! gradient->isCompressedInterpolation());
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void LayerGradientTest::ccTouchesMoved(Set * touches, Event *event)
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-06-22 11:02:43 +08:00
|
|
|
Touch* touch = (Touch*) touches->anyObject();
|
2013-06-20 14:17:10 +08:00
|
|
|
Point start = touch->getLocation();
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-07-12 18:04:32 +08:00
|
|
|
Point diff = Point(s.width/2,s.height/2) - start;
|
2013-07-11 16:38:58 +08:00
|
|
|
diff = diff.normalize();
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
LayerGradient *gradient = (LayerGradient*) getChildByTag(1);
|
2012-04-08 14:16:29 +08:00
|
|
|
gradient->setVector(diff);
|
|
|
|
}
|
|
|
|
|
2013-06-20 13:43:40 +08:00
|
|
|
std::string LayerGradientTest::title()
|
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-06-20 13:43:40 +08:00
|
|
|
string LayerGradientTest::subtitle()
|
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()
|
|
|
|
{
|
|
|
|
LayerGradient* layer = new LayerGradient;
|
2013-07-05 16:49:22 +08:00
|
|
|
layer->initWithColor(Color4B(255,0,0,255), Color4B(255,255,0,255));
|
2013-06-29 10:02:10 +08:00
|
|
|
layer->autorelease();
|
|
|
|
addChild(layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerGradientTest2::title()
|
|
|
|
{
|
|
|
|
return "LayerGradientTest 2";
|
|
|
|
}
|
|
|
|
|
|
|
|
string LayerGradientTest2::subtitle()
|
|
|
|
{
|
|
|
|
return "You should see a gradient";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// LayerGradientTest3
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
LayerGradientTest3::LayerGradientTest3()
|
|
|
|
{
|
2013-07-05 16:49:22 +08:00
|
|
|
LayerGradient* layer1 = LayerGradient::create(Color4B(255,0,0,255), Color4B(255,255,0,255));
|
2013-06-29 10:02:10 +08:00
|
|
|
addChild(layer1);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string LayerGradientTest3::title()
|
|
|
|
{
|
|
|
|
return "LayerGradientTest 3";
|
|
|
|
}
|
|
|
|
|
|
|
|
string LayerGradientTest3::subtitle()
|
|
|
|
{
|
|
|
|
return "You should see a gradient";
|
|
|
|
}
|
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
// LayerIgnoreAnchorPointPos
|
|
|
|
|
|
|
|
#define kLayerIgnoreAnchorPoint 1000
|
|
|
|
|
|
|
|
void LayerIgnoreAnchorPointPos::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
LayerColor *l = LayerColor::create(Color4B(255, 0, 0, 255), 150, 150);
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
l->setAnchorPoint(Point(0.5f, 0.5f));
|
|
|
|
l->setPosition(Point( s.width/2, s.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
MoveBy *move = MoveBy::create(2, Point(100,2));
|
2013-06-20 14:17:10 +08:00
|
|
|
MoveBy * back = (MoveBy *)move->reverse();
|
|
|
|
Sequence *seq = Sequence::create(move, back, NULL);
|
|
|
|
l->runAction(RepeatForever::create(seq));
|
2012-06-15 15:10:40 +08:00
|
|
|
this->addChild(l, 0, kLayerIgnoreAnchorPoint);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite *child = Sprite::create("Images/grossini.png");
|
2012-06-15 15:10:40 +08:00
|
|
|
l->addChild(child);
|
2013-06-20 14:17:10 +08:00
|
|
|
Size lsize = l->getContentSize();
|
2013-07-12 14:11:55 +08:00
|
|
|
child->setPosition(Point(lsize.width/2, lsize.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont *item = MenuItemFont::create("Toggle ignore anchor point", CC_CALLBACK_1(LayerIgnoreAnchorPointPos::onToggle, this));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menu = Menu::create(item, NULL);
|
2012-06-15 15:10:40 +08:00
|
|
|
this->addChild(menu);
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
menu->setPosition(Point(s.width/2, s.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void LayerIgnoreAnchorPointPos::onToggle(Object* pObject)
|
2012-06-15 15:10:40 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Node* pLayer = this->getChildByTag(kLayerIgnoreAnchorPoint);
|
2012-06-15 15:10:40 +08:00
|
|
|
bool ignore = pLayer->isIgnoreAnchorPointForPosition();
|
|
|
|
pLayer->ignoreAnchorPointForPosition(! ignore);
|
|
|
|
}
|
|
|
|
|
2012-06-12 15:14:01 +08:00
|
|
|
std::string LayerIgnoreAnchorPointPos::title()
|
|
|
|
{
|
|
|
|
return "IgnoreAnchorPoint - Position";
|
|
|
|
}
|
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
std::string LayerIgnoreAnchorPointPos::subtitle()
|
|
|
|
{
|
|
|
|
return "Ignoring Anchor Point for position";
|
|
|
|
}
|
|
|
|
|
|
|
|
// LayerIgnoreAnchorPointRot
|
|
|
|
|
|
|
|
void LayerIgnoreAnchorPointRot::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
2013-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
LayerColor *l = LayerColor::create(Color4B(255, 0, 0, 255), 200, 200);
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
l->setAnchorPoint(Point(0.5f, 0.5f));
|
|
|
|
l->setPosition(Point( s.width/2, s.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
|
|
|
this->addChild(l, 0, kLayerIgnoreAnchorPoint);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
RotateBy *rot = RotateBy::create(2, 360);
|
|
|
|
l->runAction(RepeatForever::create(rot));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite *child = Sprite::create("Images/grossini.png");
|
2012-06-15 15:10:40 +08:00
|
|
|
l->addChild(child);
|
2013-06-20 14:17:10 +08:00
|
|
|
Size lsize = l->getContentSize();
|
2013-07-12 14:11:55 +08:00
|
|
|
child->setPosition(Point(lsize.width/2, lsize.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont *item = MenuItemFont::create("Toogle ignore anchor point", CC_CALLBACK_1(LayerIgnoreAnchorPointRot::onToggle, this));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menu = Menu::create(item, NULL);
|
2012-06-15 15:10:40 +08:00
|
|
|
this->addChild(menu);
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
menu->setPosition(Point(s.width/2, s.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void LayerIgnoreAnchorPointRot::onToggle(Object* pObject)
|
2012-06-15 15:10:40 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Node* pLayer = this->getChildByTag(kLayerIgnoreAnchorPoint);
|
2012-06-15 15:10:40 +08:00
|
|
|
bool ignore = pLayer->isIgnoreAnchorPointForPosition();
|
|
|
|
pLayer->ignoreAnchorPointForPosition(! ignore);
|
|
|
|
}
|
|
|
|
|
2012-06-12 15:14:01 +08:00
|
|
|
std::string LayerIgnoreAnchorPointRot::title()
|
|
|
|
{
|
|
|
|
return "IgnoreAnchorPoint - Rotation";
|
|
|
|
}
|
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
std::string LayerIgnoreAnchorPointRot::subtitle()
|
|
|
|
{
|
|
|
|
return "Ignoring Anchor Point for rotations";
|
|
|
|
}
|
|
|
|
|
|
|
|
// LayerIgnoreAnchorPointScale
|
|
|
|
void LayerIgnoreAnchorPointScale::onEnter()
|
|
|
|
{
|
|
|
|
LayerTest::onEnter();
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
LayerColor *l = LayerColor::create(Color4B(255, 0, 0, 255), 200, 200);
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
l->setAnchorPoint(Point(0.5f, 1.0f));
|
|
|
|
l->setPosition(Point( s.width/2, s.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
ScaleBy *scale = ScaleBy::create(2, 2);
|
|
|
|
ScaleBy* back = (ScaleBy*)scale->reverse();
|
|
|
|
Sequence *seq = Sequence::create(scale, back, NULL);
|
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-06-20 14:17:10 +08:00
|
|
|
Sprite *child = Sprite::create("Images/grossini.png");
|
2012-06-15 15:10:40 +08:00
|
|
|
l->addChild(child);
|
2013-06-20 14:17:10 +08:00
|
|
|
Size lsize = l->getContentSize();
|
2013-07-12 14:11:55 +08:00
|
|
|
child->setPosition(Point(lsize.width/2, lsize.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont *item = MenuItemFont::create("Toogle ignore anchor point", CC_CALLBACK_1(LayerIgnoreAnchorPointScale::onToggle, this));
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menu = Menu::create(item, NULL);
|
2012-06-15 15:10:40 +08:00
|
|
|
this->addChild(menu);
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
menu->setPosition(Point(s.width/2, s.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void LayerIgnoreAnchorPointScale::onToggle(Object* pObject)
|
2012-06-15 15:10:40 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Node* pLayer = this->getChildByTag(kLayerIgnoreAnchorPoint);
|
2012-06-15 15:10:40 +08:00
|
|
|
bool ignore = pLayer->isIgnoreAnchorPointForPosition();
|
|
|
|
pLayer->ignoreAnchorPointForPosition(! ignore);
|
|
|
|
}
|
|
|
|
|
2012-06-12 15:14:01 +08:00
|
|
|
std::string LayerIgnoreAnchorPointScale::title()
|
|
|
|
{
|
|
|
|
return "IgnoreAnchorPoint - Scale";
|
|
|
|
}
|
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
std::string LayerIgnoreAnchorPointScale::subtitle()
|
|
|
|
{
|
|
|
|
return "Ignoring Anchor Point for scale";
|
2012-06-12 15:14:01 +08:00
|
|
|
}
|
|
|
|
|
2010-11-18 14:50:28 +08:00
|
|
|
void LayerTestScene::runThisTest()
|
|
|
|
{
|
2013-02-28 16:03:55 +08:00
|
|
|
sceneIdx = -1;
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* pLayer = nextAction();
|
2010-11-18 14:50:28 +08:00
|
|
|
addChild(pLayer);
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2012-11-20 18:00:27 +08:00
|
|
|
|
|
|
|
LayerExtendedBlendOpacityTest::LayerExtendedBlendOpacityTest()
|
|
|
|
{
|
2013-07-05 16:49:22 +08:00
|
|
|
LayerGradient* 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));
|
2013-07-12 14:11:55 +08:00
|
|
|
layer1->setPosition(Point(50,50));
|
2012-11-20 18:00:27 +08:00
|
|
|
addChild(layer1);
|
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
LayerGradient* 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));
|
2013-07-12 14:11:55 +08:00
|
|
|
layer2->setPosition(Point(100,90));
|
2012-11-20 18:00:27 +08:00
|
|
|
addChild(layer2);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
LayerGradient* layer3 = LayerGradient::create();
|
2013-07-12 14:30:26 +08:00
|
|
|
layer3->setContentSize(Size(80, 80));
|
2013-07-12 14:11:55 +08:00
|
|
|
layer3->setPosition(Point(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-05 16:49:22 +08:00
|
|
|
BlendFunc blend;
|
2012-11-20 18:00:27 +08:00
|
|
|
blend.src = GL_SRC_ALPHA;
|
|
|
|
blend.dst = GL_ONE_MINUS_SRC_ALPHA;
|
|
|
|
layer3->setBlendFunc(blend);
|
|
|
|
addChild(layer3);
|
|
|
|
}
|
|
|
|
|
|
|
|
string LayerExtendedBlendOpacityTest::title()
|
|
|
|
{
|
|
|
|
return "Extended Blend & Opacity";
|
|
|
|
}
|
|
|
|
|
|
|
|
string LayerExtendedBlendOpacityTest::subtitle()
|
|
|
|
{
|
|
|
|
return "You should see 3 layers";
|
|
|
|
}
|
|
|
|
|