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

105 lines
2.7 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( Color4B(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", Rect(0, 0, 27, 40) );
2013-06-04 17:38:43 +08:00
2013-07-12 14:11:55 +08:00
player->setPosition( Point(origin.x + player->getContentSize().width/2,
2013-06-04 17:38:43 +08:00
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", [](Object* sender){
ExtensionsTestScene *pScene = new ExtensionsTestScene();
pScene->runThisTest();
pScene->release();
});
itemBack->setColor(Color3B(0, 0, 0));
2013-07-12 14:11:55 +08:00
itemBack->setPosition(Point(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 runComponentsTestLayerTest()
{
Scene *pScene = ComponentsTestLayer::scene();
Director::sharedDirector()->replaceScene(pScene);
2013-06-04 17:38:43 +08:00
}