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"
|
|
|
|
|
|
|
|
CCScene* Bug914Layer::scene()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// 'scene' is an autorelease object.
|
2012-06-14 15:13:16 +08:00
|
|
|
CCScene *pScene = CCScene::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
// 'layer' is an autorelease object.
|
2012-06-14 15:13:16 +08:00
|
|
|
Bug914Layer* 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
|
|
|
|
pScene->addChild(layer);
|
2011-07-08 11:22:35 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// return the scene
|
|
|
|
return pScene;
|
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())
|
|
|
|
{
|
2012-06-15 15:10:40 +08:00
|
|
|
setTouchEnabled(true);
|
2012-04-19 14:35:52 +08:00
|
|
|
// ask director the the window size
|
2011-07-08 11:22:35 +08:00
|
|
|
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLayerColor *layer;
|
|
|
|
for( int i=0;i < 5;i++)
|
2011-07-08 11:22:35 +08:00
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
layer = CCLayerColor::create(ccc4(i*20, i*20, i*20,255));
|
2012-04-19 14:35:52 +08:00
|
|
|
layer->setContentSize(CCSizeMake(i*100, i*100));
|
|
|
|
layer->setPosition(ccp(size.width/2, size.height/2));
|
|
|
|
layer->setAnchorPoint(ccp(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
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLabelTTF *label = CCLabelTTF::create("Hello World", "Marker Felt", 64);
|
2013-06-08 08:21:11 +08:00
|
|
|
CCMenuItem *item1 = CCMenuItemFont::create("restart", std::bind( &Bug914Layer::restart, this, std::placeholders::_1));
|
2011-07-08 11:22:35 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenu *menu = CCMenu::create(item1, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
menu->alignItemsVertically();
|
|
|
|
menu->setPosition(ccp(size.width/2, 100));
|
|
|
|
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
|
|
|
|
label->setPosition(ccp( 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
|
|
|
}
|
|
|
|
|
|
|
|
void Bug914Layer::ccTouchesMoved(CCSet *touches, CCEvent * event)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLog("Number of touches: %d", touches->count());
|
2011-07-08 11:22:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Bug914Layer::ccTouchesBegan(CCSet *touches, CCEvent * event)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
ccTouchesMoved(touches, event);
|
2011-07-08 11:22:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Bug914Layer::restart(CCObject* sender)
|
|
|
|
{
|
|
|
|
CCDirector::sharedDirector()->replaceScene(Bug914Layer::scene());
|
|
|
|
}
|