2011-07-08 11:22:35 +08:00
|
|
|
//
|
|
|
|
// Bug-624
|
|
|
|
// http://code.google.com/p/cocos2d-iphone/issues/detail?id=624
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Bug-624.h"
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Bug624Layer
|
|
|
|
//
|
2011-07-08 11:22:35 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
bool Bug624Layer::init()
|
|
|
|
{
|
|
|
|
if(BugsTestBaseLayer::init())
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
|
|
|
auto label = LabelTTF::create("Layer1", "Marker Felt", 36);
|
2011-07-08 11:22:35 +08:00
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
label->setPosition(Point(size.width/2, size.height/2));
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(label);
|
2013-10-12 14:02:01 +08:00
|
|
|
|
2013-10-23 11:27:24 +08:00
|
|
|
auto dispatcher = EventDispatcher::getInstance();
|
|
|
|
auto listener = EventListenerAcceleration::create(CC_CALLBACK_2(Bug624Layer::onAcceleration, this));
|
|
|
|
dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2013-10-12 14:02:01 +08:00
|
|
|
|
2011-07-08 11:22:35 +08:00
|
|
|
schedule(schedule_selector(Bug624Layer::switchLayer), 5.0f);
|
|
|
|
|
|
|
|
return true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-07-08 11:22:35 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return false;
|
2011-07-08 11:22:35 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void Bug624Layer::switchLayer(float dt)
|
2011-07-08 11:22:35 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
unschedule(schedule_selector(Bug624Layer::switchLayer));
|
2011-07-08 11:22:35 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = Scene::create();
|
2012-06-14 15:13:16 +08:00
|
|
|
scene->addChild(Bug624Layer2::create(), 0);
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(TransitionFade::create(2.0f, scene, Color3B::WHITE));
|
2011-07-08 11:22:35 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void Bug624Layer::onAcceleration(Acceleration* acc, Event* event)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Layer1 accel");
|
2011-07-08 11:22:35 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Bug624Layer2
|
|
|
|
//
|
2011-07-08 11:22:35 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
bool Bug624Layer2::init()
|
|
|
|
{
|
|
|
|
if(BugsTestBaseLayer::init())
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
|
|
|
auto label = LabelTTF::create("Layer2", "Marker Felt", 36);
|
2011-07-08 11:22:35 +08:00
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
label->setPosition(Point(size.width/2, size.height/2));
|
2011-07-08 11:22:35 +08:00
|
|
|
addChild(label);
|
2013-10-12 14:02:01 +08:00
|
|
|
|
2013-10-23 11:27:24 +08:00
|
|
|
auto dispatcher = EventDispatcher::getInstance();
|
|
|
|
auto listener = EventListenerAcceleration::create(CC_CALLBACK_2(Bug624Layer2::onAcceleration, this));
|
|
|
|
dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2013-10-12 14:02:01 +08:00
|
|
|
|
|
|
|
|
2011-07-08 11:22:35 +08:00
|
|
|
schedule(schedule_selector(Bug624Layer2::switchLayer), 5.0f);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void Bug624Layer2::switchLayer(float dt)
|
2011-07-08 11:22:35 +08:00
|
|
|
{
|
|
|
|
unschedule(schedule_selector(Bug624Layer::switchLayer));
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = Scene::create();
|
2012-06-14 15:13:16 +08:00
|
|
|
scene->addChild(Bug624Layer::create(), 0);
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(TransitionFade::create(2.0f, scene, Color3B::RED));
|
2011-07-08 11:22:35 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void Bug624Layer2::onAcceleration(Acceleration* acc, Event* event)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Layer2 accel");
|
2011-07-08 11:22:35 +08:00
|
|
|
}
|