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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene* ComponentsTestLayer::scene()
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene * scene = NULL;
|
2013-06-04 17:38:43 +08:00
|
|
|
do
|
|
|
|
{
|
|
|
|
// 'scene' is an autorelease object
|
2013-06-20 14:17:10 +08:00
|
|
|
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
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
CC_BREAK_IF(! LayerColor::initWithColor( ccc4(255,255,255,255) ) );
|
2013-06-04 17:38:43 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Node *root = createGameScene();
|
2013-06-04 17:38:43 +08:00
|
|
|
CC_BREAK_IF(!root);
|
|
|
|
this->addChild(root, 0, 1);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
root->getChildByTag(1)->addComponent(ComAudio::create());
|
2013-06-04 17:38:43 +08:00
|
|
|
root->getChildByTag(1)->addComponent(PlayerController::create());
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
cocos2d::Node* ComponentsTestLayer::createGameScene()
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Node *root = NULL;
|
2013-06-04 17:38:43 +08:00
|
|
|
do
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Size visibleSize = Director::sharedDirector()->getVisibleSize();
|
|
|
|
Point origin = Director::sharedDirector()->getVisibleOrigin();
|
2013-06-04 17:38:43 +08:00
|
|
|
|
|
|
|
|
2013-06-20 14:17:10 +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) );
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
root = cocos2d::Node::create();
|
2013-06-04 17:38:43 +08:00
|
|
|
root->addChild(player, 1, 1);
|
|
|
|
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
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));
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menuBack = Menu::create(itemBack, NULL);
|
|
|
|
menuBack->setPosition(PointZero);
|
2013-06-04 17:38:43 +08:00
|
|
|
addChild(menuBack);
|
|
|
|
|
|
|
|
}while (0);
|
|
|
|
|
|
|
|
return root;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void ComponentsTestLayer::toExtensionsMainLayer(cocos2d::Object *sender)
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
|
|
|
ExtensionsTestScene *pScene = new ExtensionsTestScene();
|
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void runComponentsTestLayerTest()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene *pScene = ComponentsTestLayer::scene();
|
|
|
|
Director::sharedDirector()->replaceScene(pScene);
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|