axmol/samples/Cpp/TestCpp/Classes/ExtensionsTest/ComponentsTest/ComponentsTestScene.cpp

108 lines
2.8 KiB
C++
Raw Normal View History

2013-06-04 17:38:43 +08:00
#include "ComponentsTestScene.h"
#include "GameOverScene.h"
#include "SimpleAudioEngine.h"
#include "PlayerController.h"
#include "SceneController.h"
#include "../ExtensionsTest.h"
using namespace cocos2d;
using namespace cocos2d::extension;
ComponentsTestLayer::~ComponentsTestLayer()
{
}
ComponentsTestLayer::ComponentsTestLayer()
{
}
Scene* ComponentsTestLayer::scene()
2013-06-04 17:38:43 +08:00
{
Scene * scene = NULL;
2013-06-04 17:38:43 +08:00
do
{
// 'scene' is an autorelease object
scene = Scene::create();
2013-06-04 17:38:43 +08:00
CC_BREAK_IF(! scene);
// 'layer' is an autorelease object
ComponentsTestLayer *layer = ComponentsTestLayer::create();
CC_BREAK_IF(! layer);
// add layer as a child to scene
scene->addChild(layer);
} while (0);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool ComponentsTestLayer::init()
{
bool bRet = false;
do
{
CC_BREAK_IF(! LayerColor::initWithColor( ccc4(255,255,255,255) ) );
2013-06-04 17:38:43 +08:00
Node *root = createGameScene();
2013-06-04 17:38:43 +08:00
CC_BREAK_IF(!root);
this->addChild(root, 0, 1);
root->getChildByTag(1)->addComponent(ComAudio::create());
2013-06-04 17:38:43 +08:00
root->getChildByTag(1)->addComponent(PlayerController::create());
root->addComponent(ComAudio::create());
root->addComponent(ComAttribute::create());
2013-06-04 17:38:43 +08:00
root->addComponent(SceneController::create());
bRet = true;
} while (0);
return bRet;
}
cocos2d::Node* ComponentsTestLayer::createGameScene()
2013-06-04 17:38:43 +08:00
{
Node *root = NULL;
2013-06-04 17:38:43 +08:00
do
{
Size visibleSize = Director::sharedDirector()->getVisibleSize();
Point origin = Director::sharedDirector()->getVisibleOrigin();
2013-06-04 17:38:43 +08:00
Sprite *player = Sprite::create("components/Player.png", CCRectMake(0, 0, 27, 40) );
2013-06-04 17:38:43 +08:00
player->setPosition( ccp(origin.x + player->getContentSize().width/2,
origin.y + visibleSize.height/2) );
root = cocos2d::Node::create();
2013-06-04 17:38:43 +08:00
root->addChild(player, 1, 1);
MenuItemFont *itemBack = MenuItemFont::create("Back", CC_CALLBACK_1(ComponentsTestLayer::toExtensionsMainLayer,this));
2013-06-04 17:38:43 +08:00
itemBack->setColor(ccc3(0, 0, 0));
itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
Menu *menuBack = Menu::create(itemBack, NULL);
menuBack->setPosition(PointZero);
2013-06-04 17:38:43 +08:00
addChild(menuBack);
}while (0);
return root;
}
void ComponentsTestLayer::toExtensionsMainLayer(cocos2d::Object *sender)
2013-06-04 17:38:43 +08:00
{
ExtensionsTestScene *pScene = new ExtensionsTestScene();
pScene->runThisTest();
pScene->release();
}
void runComponentsTestLayerTest()
{
Scene *pScene = ComponentsTestLayer::scene();
Director::sharedDirector()->replaceScene(pScene);
2013-06-04 17:38:43 +08:00
}