PuzzleSDK
Bug-914.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// Import the interfaces
26#include"Bug-914.h"
27
29
30// on "init" you need to initialize your instance
32{
33 // always call "super" init
34 // Apple recommends to re-assign "self" with the "super" return value
35 if (BugsTestBase::init())
36 {
37 auto listener = EventListenerTouchAllAtOnce::create();
38 listener->onTouchesBegan = CC_CALLBACK_2(Bug914Layer::onTouchesBegan, this);
39 listener->onTouchesMoved = CC_CALLBACK_2(Bug914Layer::onTouchesMoved, this);
40 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
41
42 // ask director the the window size
43 auto size = Director::getInstance()->getWinSize();
44 LayerColor *layer;
45 for( int i=0;i < 5;i++)
46 {
47 layer = LayerColor::create(Color4B(i*20, i*20, i*20,255));
48 layer->setContentSize(Size(i*100.0f, i*100.0f));
49 layer->setPosition(size.width/2, size.height/2);
50 layer->setAnchorPoint(Vec2(0.5f, 0.5f));
51 layer->setIgnoreAnchorPointForPosition(false);
52 addChild(layer, -1-i);
53 }
54
55 // create and initialize a Label
56 auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 64.0f);
57 auto item1 = MenuItemFont::create("restart", CC_CALLBACK_1(Bug914Layer::restart, this));
58
59 auto menu = Menu::create(item1, nullptr);
60 menu->alignItemsVertically();
61 menu->setPosition(size.width/2, 100);
62 addChild(menu);
63
64 // position the label on the center of the screen
65 label->setPosition(size.width /2 , size.height/2);
66
67 // add the label as a child to this Layer
68 addChild(label);
69 return true;
70 }
71 return false;
72}
73
74void Bug914Layer::onTouchesMoved(const std::vector<Touch*>& touches, Event * event)
75{
76 log("Number of touches: %d", (int)touches.size());
77}
78
79void Bug914Layer::onTouchesBegan(const std::vector<Touch*>& touches, Event * event)
80{
81 onTouchesMoved(touches, event);
82}
83
84void Bug914Layer::restart(Ref* sender)
85{
86 Director::getInstance()->replaceScene(Bug914Layer::create());
87}
USING_NS_CC
Definition: Bug-914.cpp:28
void restart(cocos2d::Ref *sender)
Definition: Bug-914.cpp:84
virtual bool init() override
Definition: Bug-914.cpp:31
void onTouchesMoved(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
Definition: Bug-914.cpp:74
void onTouchesBegan(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
Definition: Bug-914.cpp:79