PuzzleSDK
Bug-624.cpp
浏览该文件的文档.
1/****************************************************************************
2 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
3
4 http://www.cocos2d-x.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 ****************************************************************************/
24
25//
26// Bug-624
27// http://code.google.com/p/cocos2d-iphone/issues/detail?id=624
28//
29
30#include "Bug-624.h"
31
33
35//
36// Bug624Layer
37//
40{
41 Device::setAccelerometerEnabled(false);
42}
43
45{
46 if(BugsTestBase::init())
47 {
48 auto size = Director::getInstance()->getWinSize();
49 auto label = Label::createWithTTF("Layer1", "fonts/Marker Felt.ttf", 36.0f);
50
51 label->setPosition(size.width/2, size.height/2);
52 addChild(label);
53
54 Device::setAccelerometerEnabled(true);
55 auto listener = EventListenerAcceleration::create(CC_CALLBACK_2(Bug624Layer::onAcceleration, this));
56 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
57
58 schedule(CC_SCHEDULE_SELECTOR(Bug624Layer::switchLayer), 5.0f);
59
60 return true;
61 }
62
63 return false;
64}
65
67{
68 unschedule(CC_SCHEDULE_SELECTOR(Bug624Layer::switchLayer));
69
70 auto scene = Scene::create();
71 scene->addChild(Bug624Layer2::create(), 0);
72 Director::getInstance()->replaceScene(TransitionFade::create(2.0f, scene, Color3B::WHITE));
73}
74
75void Bug624Layer::onAcceleration(Acceleration* acc, Event* event)
76{
77 log("Layer1 accel");
78}
79
81//
82// Bug624Layer2
83//
86{
87 Device::setAccelerometerEnabled(false);
88}
89
91{
92 if(BugsTestBase::init())
93 {
94 auto size = Director::getInstance()->getWinSize();
95 auto label = Label::createWithTTF("Layer2", "fonts/Marker Felt.ttf", 36.0f);
96
97 label->setPosition(size.width/2, size.height/2);
98 addChild(label);
99
100 Device::setAccelerometerEnabled(true);
101 auto listener = EventListenerAcceleration::create(CC_CALLBACK_2(Bug624Layer2::onAcceleration, this));
102 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
103
104
105 schedule(CC_SCHEDULE_SELECTOR(Bug624Layer2::switchLayer), 5.0f);
106
107 return true;
108 }
109
110 return false;
111}
112
114{
115 unschedule(CC_SCHEDULE_SELECTOR(Bug624Layer::switchLayer));
116
117 auto scene = Scene::create();
118 scene->addChild(Bug624Layer::create(), 0);
119 Director::getInstance()->replaceScene(TransitionFade::create(2.0f, scene, Color3B::RED));
120}
121
122void Bug624Layer2::onAcceleration(Acceleration* acc, Event* event)
123{
124 log("Layer2 accel");
125}
USING_NS_CC
Definition: Bug-624.cpp:32
virtual bool init() override
Definition: Bug-624.cpp:90
void switchLayer(float dt)
Definition: Bug-624.cpp:113
virtual void onAcceleration(cocos2d::Acceleration *acc, cocos2d::Event *event)
Definition: Bug-624.cpp:122
virtual ~Bug624Layer2()
Definition: Bug-624.cpp:85
virtual void onAcceleration(cocos2d::Acceleration *acc, cocos2d::Event *event)
Definition: Bug-624.cpp:75
void switchLayer(float dt)
Definition: Bug-624.cpp:66
virtual ~Bug624Layer()
Definition: Bug-624.cpp:39
virtual bool init() override
Definition: Bug-624.cpp:44