2011-07-08 11:22:35 +08:00
|
|
|
//
|
|
|
|
// HelloWorldLayer.m
|
|
|
|
// EAGLViewBug
|
|
|
|
//
|
|
|
|
// Created by Wylan Werth on 7/5/10.
|
|
|
|
// Copyright BanditBear Games 2010. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
// Import the interfaces
|
|
|
|
#include"Bug-914.h"
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene* Bug914Layer::scene()
|
2011-07-08 11:22:35 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// 'scene' is an autorelease object.
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = Scene::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
// 'layer' is an autorelease object.
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = Bug914Layer::create();
|
2011-07-08 11:22:35 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// add layer as a child to scene
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->addChild(layer);
|
2011-07-08 11:22:35 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// return the scene
|
2013-07-23 08:25:44 +08:00
|
|
|
return scene;
|
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
|
2011-07-08 11:22:35 +08:00
|
|
|
if (BugsTestBaseLayer::init())
|
|
|
|
{
|
2013-10-23 11:27:24 +08:00
|
|
|
auto dispatcher = EventDispatcher::getInstance();
|
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesBegan = CC_CALLBACK_2(Bug914Layer::onTouchesBegan, this);
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(Bug914Layer::onTouchesMoved, this);
|
|
|
|
dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2013-10-12 14:02:01 +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();
|
2013-06-20 14:17:10 +08:00
|
|
|
LayerColor *layer;
|
2012-04-19 14:35:52 +08:00
|
|
|
for( int i=0;i < 5;i++)
|
2011-07-08 11:22:35 +08:00
|
|
|
{
|
2013-07-05 16:49:22 +08:00
|
|
|
layer = LayerColor::create(Color4B(i*20, i*20, i*20,255));
|
2013-07-12 14:30:26 +08:00
|
|
|
layer->setContentSize(Size(i*100, i*100));
|
2013-07-12 14:11:55 +08:00
|
|
|
layer->setPosition(Point(size.width/2, size.height/2));
|
|
|
|
layer->setAnchorPoint(Point(0.5f, 0.5f));
|
2012-06-15 15:10:40 +08:00
|
|
|
layer->ignoreAnchorPointForPosition(false);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(layer, -1-i);
|
|
|
|
}
|
2011-07-08 11:22:35 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// create and initialize a Label
|
2013-08-16 16:05:27 +08:00
|
|
|
auto label = LabelTTF::create("Hello World", "Marker Felt", 64);
|
|
|
|
auto item1 = MenuItemFont::create("restart", CC_CALLBACK_1(Bug914Layer::restart, this));
|
2011-07-08 11:22:35 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto menu = Menu::create(item1, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
menu->alignItemsVertically();
|
2013-07-12 14:11:55 +08:00
|
|
|
menu->setPosition(Point(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
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +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
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +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
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void Bug914Layer::restart(Object* sender)
|
2011-07-08 11:22:35 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(Bug914Layer::scene());
|
2011-07-08 11:22:35 +08:00
|
|
|
}
|