Merge branch 'v3_addClearforCamera' of github.com:dabingnn/cocos2d-x into v3_addClearforCamera

This commit is contained in:
Huabing.Xu 2015-05-12 10:08:12 +08:00
commit 35940ba8ef
1 changed files with 354 additions and 156 deletions

View File

@ -1,23 +1,27 @@
#include "Scene3DTest.h"
#include "ui/CocosGUI.h"
#include <spine/spine-cocos2dx.h>
#include "../testResource.h"
#include "TerrainTest.h"
USING_NS_CC;
using namespace spine;
////////////////////////////////////////////////////////////////////////////////
// Implements Scene3DTestScene
static Vec3 camera_offset(0, 45, 60);
class Scene3DTestScene : public TestCase
class Scene3DTestScene : public TerrainWalkThru
{
public:
CREATE_FUNC(Scene3DTestScene);
void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
void onTouchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
void onTouchesEnd(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
cocos2d::EventListenerCustom* _backToForegroundListener;
#endif
private:
Scene3DTestScene();
virtual ~Scene3DTestScene();
@ -25,52 +29,58 @@ private:
void create3DWorld();
void createUI();
Node* createDialog();
void createPlayerDlg();
void createDetailDlg();
void createDescDlg();
std::vector<Camera *> _gameCameras;
Terrain *_terrain;
Player *_player;
Node* _playerDlg;
Node* _detailDlg;
Node* _descDlg;
static const int DLG_COUNT = 3;
std::vector<Node*> _dlgs;
TextureCube* _textureCube;
Skybox* _skyBox;
};
enum LAYER_DEPTH {
LAYER_DEPTH_GAME = 0,
LAYER_DEPTH_UI,
LAYER_DEPTH_ACTOR,
LAYER_DEPTH_ZOOM,
LAYER_DEPTH_COUNT,
enum GAME_LAYER {
LAYER_SKYBOX = 0,
LAYER_GAME,
LAYER_UI,
LAYER_ACTOR,
LAYER_ZOOM,
LAYER_OSD,
LAYER_COUNT,
};
static CameraFlag s_CF[LAYER_DEPTH_COUNT] = {
static CameraFlag s_CF[LAYER_COUNT] = {
CameraFlag::DEFAULT,
CameraFlag::USER1,
CameraFlag::USER2,
CameraFlag::USER3,
CameraFlag::USER4,
CameraFlag::USER5,
};
static unsigned short s_CM[LAYER_DEPTH_COUNT] = {
static unsigned short s_CM[LAYER_COUNT] = {
(unsigned short)s_CF[0],
(unsigned short)s_CF[1],
(unsigned short)s_CF[2],
(unsigned short)s_CF[3],
(unsigned short)s_CF[4],
(unsigned short)s_CF[5],
};
Scene3DTestScene::Scene3DTestScene()
: _terrain(nullptr)
, _player(nullptr)
: _playerDlg(nullptr)
, _detailDlg(nullptr)
, _descDlg(nullptr)
{
}
Scene3DTestScene::~Scene3DTestScene()
{
for (auto dlg : _dlgs) {
CC_SAFE_RELEASE(dlg);
}
}
bool Scene3DTestScene::init()
@ -78,66 +88,67 @@ bool Scene3DTestScene::init()
bool ret = false;
do
{
CC_BREAK_IF(false == TestCase::init());
CC_BREAK_IF(false == TerrainWalkThru::init());
Director::getInstance()->setDisplayStats(false);
// prepare for camera creation, we need create three custom cameras
Size visibleSize = Director::getInstance()->getVisibleSize();
_gameCameras.resize(LAYER_DEPTH_COUNT);
_gameCameras.resize(LAYER_COUNT);
// first, create a camera to look the 3d game scene
Camera *ca = Camera::createPerspective(60,visibleSize.width/visibleSize.height,0.1,200);
ca->setCameraFlag(s_CF[LAYER_DEPTH_GAME]);
ca->setDepth(LAYER_DEPTH_GAME);
_gameCameras[LAYER_DEPTH_GAME] = ca;
Camera *ca = nullptr;
auto visibleSize = Director::getInstance()->getVisibleSize();
// first, create a camera to look the skybox
ca = Camera::createPerspective(60, visibleSize.width / visibleSize.height, 10, 1000);
ca->setPosition3D(Vec3(0.f, 0.f, 50.f));
ca->setCameraFlag(s_CF[LAYER_SKYBOX]);
ca->setDepth(LAYER_SKYBOX);
_gameCameras[LAYER_SKYBOX] = ca;
this->addChild(ca);
// second, use the default camera to look 2d base ui layer
// second, create a camera to look the 3D game scene
// it has been create in TerrainWalkThru::init
ca = this->_camera;
ca->setCameraFlag(s_CF[LAYER_GAME]);
ca->setDepth(LAYER_GAME);
_gameCameras[LAYER_GAME] = ca;
// third, use the default camera to look 2D base UI layer
ca =this->getDefaultCamera();
ca->setCameraFlag(s_CF[LAYER_DEPTH_UI]);
ca->setDepth(LAYER_DEPTH_UI);
_gameCameras[LAYER_DEPTH_UI] = ca;
ca->setCameraFlag(s_CF[LAYER_UI]);
ca->setDepth(LAYER_UI);
_gameCameras[LAYER_UI] = ca;
// third, create a camera to look the 3d model in dialogs
// forth, create a camera to look the 3D model in dialogs
ca = Camera::create();
ca->setCameraFlag(s_CF[LAYER_DEPTH_ACTOR]);
ca->setDepth(LAYER_DEPTH_ACTOR);
_gameCameras[LAYER_DEPTH_ACTOR] = ca;
ca->setCameraFlag(s_CF[LAYER_ACTOR]);
ca->setDepth(LAYER_ACTOR);
_gameCameras[LAYER_ACTOR] = ca;
this->addChild(ca);
// forth, create a camera to kook the ui element over on the 3d models
// fifth, create a camera to look the UI element over on the 3D models
ca = Camera::create();
ca->setCameraFlag(s_CF[LAYER_DEPTH_ZOOM]);
ca->setDepth(LAYER_DEPTH_ZOOM);
_gameCameras[LAYER_DEPTH_ZOOM] = ca;
ca->setCameraFlag(s_CF[LAYER_ZOOM]);
ca->setDepth(LAYER_ZOOM);
_gameCameras[LAYER_ZOOM] = ca;
this->addChild(ca);
// sixth, create a camera to look the OSD UI
ca = Camera::create();
ca->setCameraFlag(s_CF[LAYER_OSD]);
ca->setDepth(LAYER_OSD);
_gameCameras[LAYER_OSD] = ca;
this->addChild(ca);
// create all object in game
create3DWorld();
createUI();
Size step = VisibleRect::getVisibleRect().size;
step.width /= (DLG_COUNT + 1);
step.height /= (DLG_COUNT + 1);
Vec2 pos = VisibleRect::leftBottom();
Node * dlg;
for (int i = 0; i < DLG_COUNT; ++i) {
dlg = createDialog();
dlg->setPosition(pos);
dlg->retain();
_dlgs.push_back(dlg);
pos.x += step.width;
pos.y += step.height;
}
// add touch callback
// auto listener = EventListenerTouchAllAtOnce::create();
// listener->onTouchesBegan = CC_CALLBACK_2(Scene3DTestScene::onTouchesBegan, this);
// listener->onTouchesMoved = CC_CALLBACK_2(Scene3DTestScene::onTouchesMoved, this);
// listener->onTouchesEnded = CC_CALLBACK_2(Scene3DTestScene::onTouchesEnd, this);
// _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
createPlayerDlg();
createDetailDlg();
createDescDlg();
_playerDlg->setVisible(false);
_detailDlg->setVisible(false);
//_terrain->setVisible(false);
ret = true;
} while (0);
@ -146,137 +157,324 @@ bool Scene3DTestScene::init()
void Scene3DTestScene::create3DWorld()
{
// Size visibleSize = Director::getInstance()->getVisibleSize();
auto camera = _gameCameras[LAYER_DEPTH_GAME];
// terrain and player has been create in TerrainWalkThru::init
// we only need override there camera mask
_terrain->setCameraMask(s_CM[LAYER_GAME]);
_player->setCameraMask(s_CM[LAYER_GAME]);
_player->setScale(_player->getScale() * 1.5);
// first, create terrain
Terrain::DetailMap r("TerrainTest/dirt.jpg");
Terrain::DetailMap g("TerrainTest/Grass2.jpg",10);
Terrain::DetailMap b("TerrainTest/road.jpg");
Terrain::DetailMap a("TerrainTest/GreenSkin.jpg",20);
Terrain::TerrainData data("TerrainTest/heightmap16.jpg",
"TerrainTest/alphamap.png",
r,g,b,a,Size(32,32),40.0f,2);
_terrain = Terrain::create(data,Terrain::CrackFixedType::SKIRT);
_terrain->setMaxDetailMapAmount(4);
_terrain->setCameraMask(s_CM[LAYER_DEPTH_GAME]);
_terrain->setDrawWire(false);
_terrain->setSkirtHeightRatio(3);
_terrain->setLODDistance(64,128,192);
this->addChild(_terrain);
// add two Sprite3D monster, one is transparent
auto monster = Sprite3D::create("Sprite3DTest/orc.c3b");
monster->setRotation3D(Vec3(0,180,0));
monster->setPosition3D(_player->getPosition3D() + Vec3(50, -10, 0));
monster->setCameraMask(s_CM[LAYER_GAME]);
monster->setOpacity(128);
this->addChild(monster);
monster = Sprite3D::create("Sprite3DTest/orc.c3b");
monster->setRotation3D(Vec3(0,180,0));
monster->setPosition3D(_player->getPosition3D() + Vec3(-50, -5, 0));
monster->setCameraMask(s_CM[LAYER_GAME]);
this->addChild(monster);
// second, create actor
_player = Player::create("Sprite3DTest/girl.c3b",camera,_terrain);
_player->setCameraMask(s_CM[LAYER_DEPTH_GAME]);
_player->setScale(0.08);
_player->setPositionY(_terrain->getHeight(_player->getPositionX(),_player->getPositionZ()));
// add a particle 3d above player
auto rootps = PUParticleSystem3D::create("Particle3D/scripts/blackHole.pu", "Particle3D/materials/pu_mediapack_01.material");
rootps->setScale(2);
rootps->setPosition3D(Vec3(0, 150, 0));
rootps->setCameraMask(s_CM[LAYER_GAME]);
auto moveby = MoveBy::create(2.0f, Vec2(50.0f, 0.0f));
auto moveby1 = MoveBy::create(2.0f, Vec2(-50.0f, 0.0f));
rootps->runAction(RepeatForever::create(Sequence::create(moveby, moveby1, nullptr)));
rootps->startParticleSystem();
auto animation = Animation3D::create("Sprite3DTest/girl.c3b","Take 001");
if (animation)
{
auto animate = Animate3D::create(animation);
_player->runAction(RepeatForever::create(animate));
}
_player->addChild(rootps, 0);
addChild(_player);
// then, create skybox
//create and set our custom shader
auto shader = GLProgram::createWithFilenames("Sprite3DTest/cube_map.vert", "Sprite3DTest/cube_map.frag");
auto state = GLProgramState::create(shader);
// third, set camera position
camera->setPosition3D(_player->getPosition3D()+camera_offset);
camera->setRotation3D(Vec3(-45,0,0));
// create the second texture for cylinder
_textureCube = TextureCube::create("Sprite3DTest/skybox/left.jpg", "Sprite3DTest/skybox/right.jpg",
"Sprite3DTest/skybox/top.jpg", "Sprite3DTest/skybox/bottom.jpg",
"Sprite3DTest/skybox/front.jpg", "Sprite3DTest/skybox/back.jpg");
_textureCube->retain();
//set texture parameters
Texture2D::TexParams tRepeatParams;
tRepeatParams.magFilter = GL_LINEAR;
tRepeatParams.minFilter = GL_LINEAR;
tRepeatParams.wrapS = GL_MIRRORED_REPEAT;
tRepeatParams.wrapT = GL_MIRRORED_REPEAT;
_textureCube->setTexParameters(tRepeatParams);
// pass the texture sampler to our custom shader
state->setUniformTexture("u_cubeTex", _textureCube);
// add skybox
_skyBox = Skybox::create();
_skyBox->retain();
_skyBox->setCameraMask(s_CM[LAYER_SKYBOX]);
_skyBox->setTexture(_textureCube);
_skyBox->setScale(700.f);
this->addChild(_skyBox);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
_backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED,
[this](EventCustom*)
{
auto state = _skyBox->getGLProgramState();
auto glProgram = state->getGLProgram();
glProgram->reset();
glProgram->initWithFilenames("Sprite3DTest/cube_map.vert", "Sprite3DTest/cube_map.frag");
glProgram->link();
glProgram->updateUniforms();
_textureCube->reloadTexture();
Texture2D::TexParams tRepeatParams;
tRepeatParams.magFilter = GL_NEAREST;
tRepeatParams.minFilter = GL_NEAREST;
tRepeatParams.wrapS = GL_MIRRORED_REPEAT;
tRepeatParams.wrapT = GL_MIRRORED_REPEAT;
_textureCube->setTexParameters(tRepeatParams);
state->setUniformTexture("u_cubeTex", _textureCube);
_skyBox->reload();
_skyBox->setTexture(_textureCube);
});
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundListener, 1);
#endif
}
void Scene3DTestScene::createUI()
{
auto showLeftDlgItem = MenuItemImage::create(s_pathClose, s_pathClose, [this](Ref* sender){
this->_dlgs[0]->setVisible(!this->_dlgs[0]->isVisible());
// add player button
auto showLeftDlgItem = MenuItemImage::create("Images/Pea.png", "Images/Pea.png", [this](Ref* sender){
this->_playerDlg->setVisible(!this->_playerDlg->isVisible());
});
showLeftDlgItem->setPosition(VisibleRect::left().x + 30, VisibleRect::top().y - 30);
auto showMidDlgItem = MenuItemImage::create(s_pathClose, s_pathClose, [this](Ref* sender){
this->_dlgs[1]->setVisible(!this->_dlgs[1]->isVisible());
// add discription button
TTFConfig ttfConfig("fonts/arial.ttf", 20);
auto descItem = MenuItemLabel::create(Label::createWithTTF(ttfConfig, "Description"),
[this](Ref* sender)
{
this->_descDlg->setVisible(!this->_descDlg->isVisible());
});
showMidDlgItem->setPosition(VisibleRect::top().x, VisibleRect::top().y - 30);
descItem->setPosition(Vec2(VisibleRect::right().x - 50, VisibleRect::top().y - 25));
auto showRightDlgItem = MenuItemImage::create(s_pathClose, s_pathClose, [this](Ref* sender){
this->_dlgs[2]->setVisible(!this->_dlgs[2]->isVisible());
});
// add back button
auto backItem = MenuItemLabel::create(Label::createWithTTF(ttfConfig, "Back"),
[this](Ref* sender){
this->getTestSuite()->backsUpOneLevel();
});
backItem->setPosition(Vec2(VisibleRect::right().x - 50, VisibleRect::bottom().y + 25));
showRightDlgItem->setPosition(VisibleRect::right().x - 30, VisibleRect::top().y - 30);
auto uiCamera = _gameCameras[LAYER_DEPTH_UI];
auto moveCameraLeft = MenuItemImage::create(s_pathClose, s_pathClose, [uiCamera](Ref* sender){
uiCamera->setPositionX(uiCamera->getPositionX() - 10);
});
moveCameraLeft->setPosition(VisibleRect::left().x + 30, VisibleRect::left().y);
auto moveCameraRight = MenuItemImage::create(s_pathClose, s_pathClose, [uiCamera](Ref* sender){
uiCamera->setPositionX(uiCamera->getPositionX() + 10);
});
moveCameraRight->setPosition(VisibleRect::right().x - 30, VisibleRect::right().y);
MenuItemImage *moveCameraLeft = nullptr, *moveCameraRight = nullptr;
// auto uiCamera = _gameCameras[LAYER_UI];
// moveCameraLeft = MenuItemImage::create(s_pathClose, s_pathClose, [uiCamera](Ref* sender){
// uiCamera->setPositionX(uiCamera->getPositionX() - 10);
// });
// moveCameraLeft->setPosition(VisibleRect::left().x + 30, VisibleRect::left().y);
//
// moveCameraRight = MenuItemImage::create(s_pathClose, s_pathClose, [uiCamera](Ref* sender){
// uiCamera->setPositionX(uiCamera->getPositionX() + 10);
// });
// moveCameraRight->setPosition(VisibleRect::right().x - 30, VisibleRect::right().y);
auto menu = Menu::create(showLeftDlgItem,
showMidDlgItem,
showRightDlgItem,
descItem,
backItem,
moveCameraLeft,
moveCameraRight,
nullptr);
menu->setPosition(Vec2::ZERO);
menu->setCameraMask(s_CM[LAYER_DEPTH_UI], true);
menu->setCameraMask(s_CM[LAYER_UI], true);
this->addChild(menu);
}
Node* Scene3DTestScene::createDialog()
void Scene3DTestScene::createPlayerDlg()
{
// create dialog layer
int layerW = 240;
int layerH = 160;
int margin = 10;
static char clr = 0x3f;
auto layer = LayerColor::create(Color4B(clr, clr, clr, 255), layerW, layerH);
clr = clr << 1;
layer->setVisible(false);
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(s_s9s_ui_plist);
// add 2d ui element on dialog:
// actor background
auto actorBg = LayerColor::create(Color4B(0, 0, 128, 255), layerW / 2 - 2 * margin, layerH - 2 * margin - 16);
actorBg->setPosition(margin, margin);
layer->addChild(actorBg);
Size dlgSize(190, 240);
Vec2 pos = VisibleRect::center();
float margin = 10;
// first, create dialog ui part, include background, title and buttons
_playerDlg = ui::Scale9Sprite::createWithSpriteFrameName("button_actived.png");
_playerDlg->setContentSize(dlgSize);
_playerDlg->setAnchorPoint(Vec2(1, 0.5));
pos.y -= margin;
pos.x -= margin;
_playerDlg->setPosition(pos);
// title
auto title = Label::createWithTTF("Actor Dialog","fonts/arial.ttf",16);
title->setPosition(layerW / 2, layerH - margin);
layer->addChild(title);
auto title = Label::createWithTTF("Player Dialog","fonts/arial.ttf",16);
title->setPosition(dlgSize.width / 2, dlgSize.height - margin * 2);
_playerDlg->addChild(title);
// add layer to scene and set camera mask
layer->setCameraMask(s_CM[LAYER_DEPTH_UI]);
this->addChild(layer);
// player background
Size bgSize(110, 180);
Vec2 bgPos(margin, dlgSize.height / 2 - margin);
auto playerBg = ui::Scale9Sprite::createWithSpriteFrameName("item_bg.png");
playerBg->setContentSize(bgSize);
playerBg->setAnchorPoint(Vec2(0, 0.5));
playerBg->setPosition(bgPos);
_playerDlg->addChild(playerBg);
// add actor, which on dialog layer
// item background and item
Size itemSize(48, 48);
Vec2 itemAnchor(0, 1);
Vec2 itemPos(bgPos.x + bgSize.width + margin, bgPos.y + bgSize.height / 2);
auto itemBg = ui::Scale9Sprite::createWithSpriteFrameName("item_bg.png");
itemBg->setContentSize(itemSize);
itemBg->setAnchorPoint(itemAnchor);
itemBg->setPosition(itemPos);
_playerDlg->addChild(itemBg);
auto item = ui::Button::create("crystal.png", "", "", ui::TextureResType::PLIST);
item->setScale(1.5);
item->setAnchorPoint(itemAnchor);
item->setPosition(itemPos);
item->addClickEventListener([this](Ref* sender){
this->_detailDlg->setVisible(!this->_detailDlg->isVisible());
});
_playerDlg->addChild(item);
// after add ui element, add player dialog to scene
_playerDlg->setCameraMask(s_CM[LAYER_UI]);
this->addChild(_playerDlg);
// second, add 3d actor, which on dialog layer
std::string filename = "Sprite3DTest/girl.c3b";
auto girl = Sprite3D::create(filename);
girl->setScale(0.5);
girl->setPosition(layerW / 4, margin * 3);
girl->setCameraMask(s_CM[LAYER_DEPTH_ACTOR]);
layer->addChild(girl);
girl->setPosition(bgSize.width / 2, margin * 2);
girl->setCameraMask(s_CM[LAYER_ACTOR]);
playerBg->addChild(girl);
// add zoom in/out button, which is 2d ui element and over 3d actor
auto zoomIn = MenuItemImage::create(s_pathClose, s_pathClose, [girl](Ref* sender){
// third, add zoom in/out button, which is 2d ui element and over 3d actor
ui::Button* zoomIn = ui::Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
zoomIn->setScale(0.5);
zoomIn->setAnchorPoint(Vec2(1, 1));
zoomIn->setPosition(Vec2(bgSize.width / 2 - margin / 2, bgSize.height - margin));
zoomIn->addClickEventListener([girl](Ref* sender){
girl->setScale(girl->getScale() * 2);
});
zoomIn->setPosition(margin, layerH - margin);
zoomIn->setTitleText("Zoom In");
zoomIn->setCameraMask(s_CM[LAYER_ZOOM]);
playerBg->addChild(zoomIn);
auto zoomOut = MenuItemImage::create(s_pathClose, s_pathClose, [girl](Ref* sender){
ui::Button* zoomOut = ui::Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
zoomOut->setScale(0.5);
zoomOut->setAnchorPoint(Vec2(0, 1));
zoomOut->setPosition(Vec2(bgSize.width / 2 + margin / 2, bgSize.height - margin));
zoomOut->addClickEventListener([girl](Ref* sender){
girl->setScale(girl->getScale() / 2);
});
zoomOut->setPosition(layerW / 2 - margin, layerH - margin);
zoomOut->setTitleText("Zoom Out");
zoomOut->setCameraMask(s_CM[LAYER_ZOOM]);
playerBg->addChild(zoomOut);
}
auto menu = Menu::create(zoomIn, zoomOut, nullptr);
menu->setPosition(Vec2::ZERO);
menu->setCameraMask(s_CM[LAYER_DEPTH_ZOOM]);
layer->addChild(menu);
void Scene3DTestScene::createDetailDlg()
{
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(s_s9s_ui_plist);
return layer;
Size dlgSize(190, 240);
Vec2 pos = VisibleRect::center();
float margin = 10;
// create dialog
_detailDlg = ui::Scale9Sprite::createWithSpriteFrameName("button_actived.png");
_detailDlg->setContentSize(dlgSize);
_detailDlg->setAnchorPoint(Vec2(0, 0.5));
_detailDlg->setOpacity(224);
pos.y -= margin;
pos.x += margin;
_detailDlg->setPosition(pos);
// title
auto title = Label::createWithTTF("Detail Dialog","fonts/arial.ttf",16);
title->setPosition(dlgSize.width / 2, dlgSize.height - margin * 2);
_detailDlg->addChild(title);
// add a spine ffd animation on it
auto skeletonNode = SkeletonAnimation::createWithFile("spine/goblins-ffd.json", "spine/goblins-ffd.atlas", 1.5f);
skeletonNode->setAnimation(0, "walk", true);
skeletonNode->setSkin("goblin");
skeletonNode->setScale(0.25);
Size windowSize = Director::getInstance()->getWinSize();
skeletonNode->setPosition(Vec2(dlgSize.width / 2, 20));
_detailDlg->addChild(skeletonNode);
scheduleUpdate();
EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [skeletonNode] (Touch* touch, Event* event) -> bool {
if (!skeletonNode->getDebugBonesEnabled())
skeletonNode->setDebugBonesEnabled(true);
else if (skeletonNode->getTimeScale() == 1)
skeletonNode->setTimeScale(0.3f);
else
{
skeletonNode->setTimeScale(1);
skeletonNode->setDebugBonesEnabled(false);
}
return true;
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
// after add ui element, add dialog to scene
_detailDlg->setCameraMask(s_CM[LAYER_UI]);
this->addChild(_detailDlg);
}
void Scene3DTestScene::createDescDlg()
{
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(s_s9s_ui_plist);
Size dlgSize(440, 240);
Vec2 pos = VisibleRect::center();
float margin = 10;
// create dialog
_descDlg = ui::Scale9Sprite::createWithSpriteFrameName("button_actived.png");
_descDlg->setContentSize(dlgSize);
_descDlg->setOpacity(224);
_descDlg->setPosition(pos);
// title
auto title = Label::createWithTTF("Description Dialog","fonts/arial.ttf",16);
title->setPosition(dlgSize.width / 2, dlgSize.height - margin * 2);
_descDlg->addChild(title);
// add a label to retain description text
Size textSize(400, 220);
auto desc =
"Scene 3D test for 2D and 3D mix rendering.\n"
"\n"
"- Game world composite with terrain, skybox and 3D objects.\n"
"- UI composite with 2D nodes.\n"
"- Click the icon at the topleft conner, will show a player dialog which "
"there is a 3D sprite on it.\n"
"- There are two button to zoom the player model, which should keep above "
"on 3D model.\n"
" - This description dialog should above all other elements.\n"
"\n"
"Click \"Description\" button to hide this dialog.\n";
auto text = Label::createWithSystemFont(desc, "Helvetica", 12, textSize);
text->setAnchorPoint(Vec2(0, 1));
text->setPosition(margin, dlgSize.height - (20 + margin));
_descDlg->addChild(text);
// after add ui element, add dialog to scene
_descDlg->setCameraMask(s_CM[LAYER_OSD]);
this->addChild(_descDlg);
}
////////////////////////////////////////////////////////////////////////////////