Scene* Scene::load(const char* filePath) { if (endsWith(filePath, ".gpb", true)) { Scene* scene = NULL; Bundle* bundle = Bundle::create(filePath); if (bundle) { scene = bundle->loadScene(); SAFE_RELEASE(bundle); } return scene; } return SceneLoader::load(filePath); }
void Audio3DTest::initialize() { setMultiTouch(true); _font = Font::create("res/common/arial18.gpb"); // Load game scene from file Bundle* bundle = Bundle::create("res/common/box.gpb"); _scene = bundle->loadScene(); SAFE_RELEASE(bundle); // Get light node Node* lightNode = _scene->findNode("directionalLight1"); Light* light = lightNode->getLight(); // Initialize box model Node* boxNode = _scene->findNode("box"); Model* boxModel = boxNode->getModel(); Material* boxMaterial = boxModel->setMaterial("res/common/box.material"); boxMaterial->getParameter("u_lightColor")->setValue(light->getColor()); boxMaterial->getParameter("u_lightDirection")->setValue(lightNode->getForwardVectorView()); // Remove the cube from the scene but keep a reference to it. _cubeNode = boxNode; _cubeNode->addRef(); _scene->removeNode(_cubeNode); loadGrid(_scene); // Initialize cameraa Vector3 cameraPosition(5, 5, 1); if (Camera* camera = _scene->getActiveCamera()) { camera->getNode()->getTranslation(&cameraPosition); } _fpCamera.initialize(); _fpCamera.setPosition(cameraPosition); _scene->addNode(_fpCamera.getRootNode()); _scene->setActiveCamera(_fpCamera.getCamera()); _gamepad = getGamepad(0); GP_ASSERT(_gamepad); _gamepad->getForm()->setConsumeInputEvents(false); }
void SpaceshipGame::initialize() { // TODO: Not working on iOS // Display the gameplay splash screen for at least 1 second. displayScreen(this, &SpaceshipGame::drawSplash, NULL, 1000L); // Create our render state block that will be reused across all materials _stateBlock = RenderState::StateBlock::create(); _stateBlock->setDepthTest(true); _stateBlock->setCullFace(true); _stateBlock->setBlend(true); _stateBlock->setBlendSrc(RenderState::BLEND_SRC_ALPHA); _stateBlock->setBlendDst(RenderState::BLEND_ONE_MINUS_SRC_ALPHA); // Load our scene from file Bundle* bundle = Bundle::create("res/spaceship.gpb"); _scene = bundle->loadScene(); SAFE_RELEASE(bundle); // Update the aspect ratio for our scene's camera to match the current device resolution _scene->getActiveCamera()->setAspectRatio((float)getWidth() / (float)getHeight()); // Initialize scene data initializeSpaceship(); initializeEnvironment(); // Create a background audio track _backgroundSound = AudioSource::create("res/background.ogg"); if (_backgroundSound) _backgroundSound->setLooped(true); // Create font _font = Font::create("res/airstrip28.gpb"); // Store camera node _cameraNode = _scene->findNode("camera1"); // Store initial ship and camera positions _initialShipPos = _shipGroupNode->getTranslation(); _initialShipRot = _shipGroupNode->getRotation(); _initialCameraPos = _cameraNode->getTranslation(); }
void TemplateGame::initialize() { // Load game scene from file Bundle* bundle = Bundle::create("res/box.gpb"); _scene = bundle->loadScene(); SAFE_RELEASE(bundle); // Set the aspect ratio for the scene's camera to match the current resolution _scene->getActiveCamera()->setAspectRatio((float)getWidth() / (float)getHeight()); // Get light node Node* lightNode = _scene->findNode("directionalLight"); Light* light = lightNode->getLight(); // Initialize box model Node* boxNode = _scene->findNode("box"); Model* boxModel = boxNode->getModel(); Material* boxMaterial = boxModel->setMaterial("res/box.material"); boxMaterial->getParameter("u_ambientColor")->setValue(_scene->getAmbientColor()); boxMaterial->getParameter("u_ambientColor")->setValue(_scene->getAmbientColor()); boxMaterial->getParameter("u_lightColor")->setValue(light->getColor()); boxMaterial->getParameter("u_lightDirection")->setValue(lightNode->getForwardVectorView()); }
static int lua_Bundle_loadScene(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 1: { if ((lua_type(state, 1) == LUA_TUSERDATA)) { Bundle* instance = getInstance(state); void* returnPtr = ((void*)instance->loadScene()); if (returnPtr) { gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject)); object->instance = returnPtr; object->owns = true; luaL_getmetatable(state, "Scene"); lua_setmetatable(state, -2); } else { lua_pushnil(state); } return 1; } lua_pushstring(state, "lua_Bundle_loadScene - Failed to match the given parameters to a valid function signature."); lua_error(state); break; } case 2: { if ((lua_type(state, 1) == LUA_TUSERDATA) && (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL)) { // Get parameter 1 off the stack. const char* param1 = gameplay::ScriptUtil::getString(2, false); Bundle* instance = getInstance(state); void* returnPtr = ((void*)instance->loadScene(param1)); if (returnPtr) { gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject)); object->instance = returnPtr; object->owns = true; luaL_getmetatable(state, "Scene"); lua_setmetatable(state, -2); } else { lua_pushnil(state); } return 1; } lua_pushstring(state, "lua_Bundle_loadScene - Failed to match the given parameters to a valid function signature."); lua_error(state); break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 1 or 2)."); lua_error(state); break; } } return 0; }