2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
http://www.cocos2d-x.org
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +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-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +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.
|
|
|
|
****************************************************************************/
|
2011-07-08 11:22:35 +08:00
|
|
|
|
|
|
|
// Import the interfaces
|
2021-12-28 16:06:23 +08:00
|
|
|
#include "Bug-914.h"
|
2011-07-08 11:22:35 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
|
2011-07-08 11:22:35 +08:00
|
|
|
// on "init" you need to initialize your instance
|
|
|
|
bool Bug914Layer::init()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// always call "super" init
|
|
|
|
// Apple recommends to re-assign "self" with the "super" return value
|
2015-04-03 14:31:03 +08:00
|
|
|
if (BugsTestBase::init())
|
2011-07-08 11:22:35 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
2013-10-23 11:27:24 +08:00
|
|
|
listener->onTouchesBegan = CC_CALLBACK_2(Bug914Layer::onTouchesBegan, this);
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(Bug914Layer::onTouchesMoved, this);
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// ask director the the window size
|
2013-08-16 16:05:27 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
LayerColor* layer;
|
|
|
|
for (int i = 0; i < 5; i++)
|
2011-07-08 11:22:35 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
layer = LayerColor::create(Color4B(i * 20, i * 20, i * 20, 255));
|
|
|
|
layer->setContentSize(Size(i * 100.0f, i * 100.0f));
|
|
|
|
layer->setPosition(size.width / 2, size.height / 2);
|
2014-05-15 01:07:09 +08:00
|
|
|
layer->setAnchorPoint(Vec2(0.5f, 0.5f));
|
2016-04-25 19:43:42 +08:00
|
|
|
layer->setIgnoreAnchorPointForPosition(false);
|
2021-12-28 16:06:23 +08:00
|
|
|
addChild(layer, -1 - i);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-07-08 11:22:35 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// create and initialize a Label
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 64.0f);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto item1 = MenuItemFont::create("restart", CC_CALLBACK_1(Bug914Layer::restart, this));
|
2011-07-08 11:22:35 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto menu = Menu::create(item1, nullptr);
|
2012-04-19 14:35:52 +08:00
|
|
|
menu->alignItemsVertically();
|
2021-12-28 16:06:23 +08:00
|
|
|
menu->setPosition(size.width / 2, 100);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(menu);
|
2011-07-08 11:22:35 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// position the label on the center of the screen
|
2021-12-28 16:06:23 +08:00
|
|
|
label->setPosition(size.width / 2, size.height / 2);
|
2011-07-08 11:22:35 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// add the label as a child to this Layer
|
|
|
|
addChild(label);
|
2011-07-08 11:22:35 +08:00
|
|
|
return true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
return false;
|
2011-07-08 11:22:35 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void Bug914Layer::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
|
2011-07-08 11:22:35 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
log("Number of touches: %d", (int)touches.size());
|
2011-07-08 11:22:35 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void Bug914Layer::onTouchesBegan(const std::vector<Touch*>& touches, Event* event)
|
2011-07-08 11:22:35 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
onTouchesMoved(touches, event);
|
2011-07-08 11:22:35 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void Bug914Layer::restart(Ref* sender)
|
2011-07-08 11:22:35 +08:00
|
|
|
{
|
2015-04-09 14:59:34 +08:00
|
|
|
Director::getInstance()->replaceScene(Bug914Layer::create());
|
2011-07-08 11:22:35 +08:00
|
|
|
}
|