axmol/samples/Cpp/TestCpp/Classes/BugsTest/Bug-914.cpp

80 lines
2.2 KiB
C++
Raw Normal View History

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"
Scene* Bug914Layer::scene()
2011-07-08 11:22:35 +08:00
{
// 'scene' is an autorelease object.
Scene *pScene = Scene::create();
// 'layer' is an autorelease object.
Bug914Layer* layer = Bug914Layer::create();
2011-07-08 11:22:35 +08:00
// add layer as a child to scene
pScene->addChild(layer);
2011-07-08 11:22:35 +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()
{
// 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())
{
setTouchEnabled(true);
// ask director the the window size
Size size = Director::sharedDirector()->getWinSize();
LayerColor *layer;
for( int i=0;i < 5;i++)
2011-07-08 11:22:35 +08:00
{
layer = LayerColor::create(ccc4(i*20, i*20, i*20,255));
layer->setContentSize(CCSizeMake(i*100, i*100));
layer->setPosition(ccp(size.width/2, size.height/2));
layer->setAnchorPoint(ccp(0.5f, 0.5f));
layer->ignoreAnchorPointForPosition(false);
addChild(layer, -1-i);
}
2011-07-08 11:22:35 +08:00
// create and initialize a Label
LabelTTF *label = LabelTTF::create("Hello World", "Marker Felt", 64);
MenuItem *item1 = MenuItemFont::create("restart", CC_CALLBACK_1(Bug914Layer::restart, this));
2011-07-08 11:22:35 +08:00
Menu *menu = Menu::create(item1, NULL);
menu->alignItemsVertically();
menu->setPosition(ccp(size.width/2, 100));
addChild(menu);
2011-07-08 11:22:35 +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
// add the label as a child to this Layer
addChild(label);
2011-07-08 11:22:35 +08:00
return true;
}
return false;
2011-07-08 11:22:35 +08:00
}
void Bug914Layer::ccTouchesMoved(Set *touches, Event * event)
2011-07-08 11:22:35 +08:00
{
CCLog("Number of touches: %d", touches->count());
2011-07-08 11:22:35 +08:00
}
void Bug914Layer::ccTouchesBegan(Set *touches, Event * event)
2011-07-08 11:22:35 +08:00
{
ccTouchesMoved(touches, event);
2011-07-08 11:22:35 +08:00
}
void Bug914Layer::restart(Object* sender)
2011-07-08 11:22:35 +08:00
{
Director::sharedDirector()->replaceScene(Bug914Layer::scene());
2011-07-08 11:22:35 +08:00
}