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-07-05 16:49:22 +08:00
|
|
|
CC_BREAK_IF(! LayerColor::initWithColor( Color4B(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-07-12 14:30:26 +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) );
|
|
|
|
|
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-21 14:15:20 +08:00
|
|
|
MenuItemFont *itemBack = MenuItemFont::create("Back", [](Object* sender){
|
|
|
|
ExtensionsTestScene *pScene = new ExtensionsTestScene();
|
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->release();
|
|
|
|
});
|
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
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));
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|