void CharacterGame::initialize() { // Enable multi-touch (only affects devices that support multi-touch). setMultiTouch(true); // Display the gameplay splash screen for at least 1 second. displayScreen(this, &CharacterGame::drawSplash, NULL, 1000L); // Load the font. _font = Font::create("res/arial40.gpb"); // Load scene. _scene = Scene::load("res/scene.scene"); // Update the aspect ratio for our scene's camera to match the current device resolution. _scene->getActiveCamera()->setAspectRatio((float)getWidth() / (float)getHeight()); // Initialize the physics character. initializeCharacter(); // Initialize the gamepad. initializeGamepad(); // Initialize scene. _scene->visit(this, &CharacterGame::initializeScene); }
void GestureSample::initialize() { setMultiTouch(true); // Load font _font = Font::create("res/common/arial18.gpb"); assert(_font); bool anySupported = false; if (isGestureSupported(Gesture::GESTURE_TAP)) { anySupported = true; registerGesture(Gesture::GESTURE_TAP); GP_ASSERT(isGestureRegistered(Gesture::GESTURE_TAP)); } if (isGestureSupported(Gesture::GESTURE_SWIPE)) { anySupported = true; registerGesture(Gesture::GESTURE_SWIPE); GP_ASSERT(isGestureRegistered(Gesture::GESTURE_SWIPE)); } if (isGestureSupported(Gesture::GESTURE_PINCH)) { anySupported = true; registerGesture(Gesture::GESTURE_PINCH); GP_ASSERT(isGestureRegistered(Gesture::GESTURE_PINCH)); } GP_ASSERT(anySupported == isGestureSupported(Gesture::GESTURE_ANY_SUPPORTED)); }
void BillboardSample::initialize() { setMultiTouch(true); // Create the font and scene _font = Font::create("res/ui/arial.gpb"); _scene = Scene::create(); // Initialize the camera _camera.initialize(0.1f, 100, 45); _camera.setPosition(Vector3(0, BILLBOARD_HEIGHT * 1.5f, GROUND_WIDTH / 2.0f)); _camera.rotate(0.0f, -MATH_DEG_TO_RAD(10)); _scene->addNode(_camera.getRootNode()); _scene->setActiveCamera(_camera.getCamera()); // Load the ground loadGround(); // Load billboards loadBillboards(); _gamepad = getGamepad(0); // This is needed because the virtual gamepad is shared between all samples. // SamplesGame always ensures the virtual gamepad is disabled when a sample is exited. if (_gamepad && _gamepad->isVirtual()) _gamepad->getForm()->setEnabled(true); }
void FormsSample::initialize() { setMultiTouch(true); setVsync(false); _formSelect = Form::create("res/common/forms/formSelect.form"); _formSelect->setFocus(); RadioButton* form0Button = static_cast<RadioButton*>(_formSelect->getControl("form0")); form0Button->addListener(this, Control::Listener::CLICK); RadioButton* form1Button = static_cast<RadioButton*>(_formSelect->getControl("form1")); form1Button->addListener(this, Control::Listener::CLICK); RadioButton* form2Button = static_cast<RadioButton*>(_formSelect->getControl("form2")); form2Button->addListener(this, Control::Listener::CLICK); RadioButton* form3Button = static_cast<RadioButton*>(_formSelect->getControl("form3")); form3Button->addListener(this, Control::Listener::CLICK); RadioButton* form4Button = static_cast<RadioButton*>(_formSelect->getControl("form4")); form4Button->addListener(this, Control::Listener::CLICK); RadioButton* form5Button = static_cast<RadioButton*>(_formSelect->getControl("form5")); form5Button->addListener(this, Control::Listener::CLICK); for (unsigned int i = 0; i < _formFiles.size(); i++) { Form* form = Form::create(_formFiles[i]); form->setEnabled(false); _forms.push_back(form); } _formIndex = 0; // Create a form programmatically. createSampleForm(); Button* button = static_cast<Button*>(_forms[0]->getControl("testButton")); button->setFocus(); // Create a scene with a camera node. Camera* camera = Camera::createPerspective(45.0f, (float)getWidth() / (float)getHeight(), 0.25f, 100.0f); _scene = Scene::create(); Node* cameraNode = _scene->addNode("Camera"); cameraNode->setCamera(camera); _scene->setActiveCamera(camera); SAFE_RELEASE(camera); _formNodeParent = _scene->addNode("FormParent"); _formNode = Node::create("Form"); _formNodeParent->addChild(_formNode); formChanged(); _gamepad = getGamepad(0); // This is needed because the virtual gamepad is shared between all samples. // SamplesGame always ensures the virtual gamepad is disabled when a sample is exited. if (_gamepad && _gamepad->isVirtual()) _gamepad->getForm()->setEnabled(true); }
void InputSample::initialize() { setMultiTouch(true); // Load font _font = Font::create("res/ui/arial.gpb"); assert(_font); // Reuse part of the gamepad texture as the crosshair in this sample. _crosshair = SpriteBatch::create("res/png/gamepad.png"); _crosshairDstRect.set(0, 0, 256, 256); _crosshairSrcRect.set(256, 0, 256, 256); _crosshairLowerLimit.set(-_crosshairSrcRect.width / 2.0f, -_crosshairSrcRect.height / 2.0f); _crosshairUpperLimit.set((float)getWidth(), (float)getHeight()); _crosshairUpperLimit += _crosshairLowerLimit; // Create input sample controls _keyboardState = false; _inputSampleControls = Form::create("res/common/inputs.form"); static_cast<Button*>(_inputSampleControls->getControl("showKeyboardButton"))->addListener(this, Listener::CLICK); static_cast<Button*>(_inputSampleControls->getControl("captureMouseButton"))->addListener(this, Listener::CLICK); if (!hasMouse()) { static_cast<Button*>(_inputSampleControls->getControl("captureMouseButton"))->setVisible(false); } _inputSampleControls->getControl("restoreMouseLabel")->setVisible(false); _mousePoint.set(-100, -100); // Create a 3D form that responds to raw sensor inputs. // For this, we will need a scene with a camera node. Camera* camera = Camera::createPerspective(45.0f, (float)getWidth() / (float)getHeight(), 0.25f, 100.0f); _scene = Scene::create(); Node* cameraNode = _scene->addNode("Camera"); cameraNode->setCamera(camera); _scene->setActiveCamera(camera); SAFE_RELEASE(camera); _formNodeParent = _scene->addNode("FormParent"); _formNode = Node::create("Form"); _formNodeParent->addChild(_formNode); Theme* theme = _inputSampleControls->getTheme(); Form* form = Form::create("testForm", theme->getStyle("basicContainer"), Layout::LAYOUT_ABSOLUTE); form->setSize(225, 100); Label* label = Label::create("sensorLabel", theme->getStyle("iconNoBorder")); label->setPosition(25, 15); label->setSize(175, 50); label->setText("Raw sensor response (accel/gyro)"); form->addControl(label); label->release(); _formNode->setScale(0.0015f, 0.0015f, 1.0f); _formNodeRestPosition.set(0, 0, -1.5f); _formNodeParent->setTranslation(_formNodeRestPosition); _formNode->setTranslation(-0.2f, -0.2f, 0); _formNode->setDrawable(form); form->release(); }
void GamepadSample::initialize() { setMultiTouch(true); _gamepad = getGamepad(0); // This is needed because the virtual gamepad is shared between all samples. // SamplesGame always ensures the virtual gamepad is disabled when a sample is exited. if (_gamepad && _gamepad->isVirtual()) _gamepad->getForm()->setEnabled(true); _font = Font::create("res/ui/arial.gpb"); _status = "Looking for gamepads..."; }
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 Geoms::initialize() { setMultiTouch(true); // Load game scene from file _scene = Scene::load("res/box.gpb"); // Set the aspect ratio for the scene's camera to match the current resolution _scene->getActiveCamera()->setAspectRatio(getAspectRatio()); // 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_lightColor")->setValue(light->getColor()); boxMaterial->getParameter("u_lightDirection")->setValue(lightNode->getForwardVectorView()); }
void ParticlesGame::initialize() { // Display the gameplay splash screen displayScreen(this, &ParticlesGame::drawSplash, NULL, 250L); setMultiTouch(true); // Set keyboard state. _wDown = _aDown = _sDown = _dDown = false; _touched = false; _prevX = _prevY = 0; // Create a scene with a camera node. // The camera node is a child of a node at the same location as the particle emitter. // The camera node is offset from its parent, looking straight at it. // That way, when we rotate the parent node, the camera stays aimed at the particle emitter. _scene = Scene::create(); Node* cameraNode = _scene->addNode("Camera"); _cameraParent = _scene->addNode("CameraParent"); _cameraParent->addChild(cameraNode); Camera* camera = Camera::createPerspective(45.0f, (float)getWidth() / (float)getHeight(), 0.25f, 1000.0f); cameraNode->setCamera(camera); cameraNode->setTranslation(0.0f, 0.0f, ZOOM_DEFAULT); _scene->setActiveCamera(camera); SAFE_RELEASE(camera); addGrid(61); // Create a font for drawing the framerate. _font = Font::create("res/ui/arial.gpb"); // Load the form for editing ParticleEmitters. _form = Form::create("res/editor.form"); _form->setConsumeInputEvents(false); //_form->setState(Control::FOCUS); // Store pointers to UI controls we care about. _startRed = (Slider*)_form->getControl("startRed"); _startGreen = (Slider*)_form->getControl("startGreen"); _startBlue = (Slider*)_form->getControl("startBlue"); _startAlpha = (Slider*)_form->getControl("startAlpha"); _endRed = (Slider*)_form->getControl("endRed"); _endGreen = (Slider*)_form->getControl("endGreen"); _endBlue = (Slider*)_form->getControl("endBlue"); _endAlpha = (Slider*)_form->getControl("endAlpha"); _particleProperties = (Container*)_form->getControl("particleProperties"); _startMin = (Slider*)_form->getControl("startMin"); _startMax = (Slider*)_form->getControl("startMax"); _endMin = (Slider*)_form->getControl("endMin"); _endMax = (Slider*)_form->getControl("endMax"); _energyMin = (Slider*)_form->getControl("energyMin"); _energyMax = (Slider*)_form->getControl("energyMax"); _emissionRate = (Slider*)_form->getControl("emissionRate"); _started = (CheckBox*)_form->getControl("started"); _reset = (Button*)_form->getControl("reset"); _emit = (Button*)_form->getControl("emit"); _zoomIn = (Button*)_form->getControl("zoomIn"); _zoomOut = (Button*)_form->getControl("zoomOut"); _save = (Button*)_form->getControl("save"); _load = (Button*)_form->getControl("load"); _burstSize = (Slider*)_form->getControl("burstSize"); _posVarX = (Slider*)_form->getControl("posVarX"); _posVarY = (Slider*)_form->getControl("posVarY"); _posVarZ = (Slider*)_form->getControl("posVarZ"); _velX = (Slider*)_form->getControl("velocityX"); _velY = (Slider*)_form->getControl("velocityY"); _velZ = (Slider*)_form->getControl("velocityZ"); _velVarX = (Slider*)_form->getControl("velocityVarX"); _velVarY = (Slider*)_form->getControl("velocityVarY"); _velVarZ = (Slider*)_form->getControl("velocityVarZ"); _accelX = (Slider*)_form->getControl("accelX"); _accelY = (Slider*)_form->getControl("accelY"); _accelZ = (Slider*)_form->getControl("accelZ"); _accelVarX = (Slider*)_form->getControl("accelVarX"); _accelVarY = (Slider*)_form->getControl("accelVarY"); _accelVarZ = (Slider*)_form->getControl("accelVarZ"); _spinSpeedMin = (Slider*)_form->getControl("spinSpeedMin"); _spinSpeedMax = (Slider*)_form->getControl("spinSpeedMax"); _axisX = (Slider*)_form->getControl("axisX"); _axisY = (Slider*)_form->getControl("axisY"); _axisZ = (Slider*)_form->getControl("axisZ"); _axisVarX = (Slider*)_form->getControl("axisVarX"); _axisVarY = (Slider*)_form->getControl("axisVarY"); _axisVarZ = (Slider*)_form->getControl("axisVarZ"); _rotationSpeedMin = (Slider*)_form->getControl("rotationSpeedMin"); _rotationSpeedMax = (Slider*)_form->getControl("rotationSpeedMax"); _vsync = (CheckBox*)_form->getControl("vsync"); // Listen for UI events. _startRed->addListener(this, Listener::VALUE_CHANGED); _startGreen->addListener(this, Listener::VALUE_CHANGED); _startBlue->addListener(this, Listener::VALUE_CHANGED); _startAlpha->addListener(this, Listener::VALUE_CHANGED); _endRed->addListener(this, Listener::VALUE_CHANGED); _endGreen->addListener(this, Listener::VALUE_CHANGED); _endBlue->addListener(this, Listener::VALUE_CHANGED); _endAlpha->addListener(this, Listener::VALUE_CHANGED); _startMin->addListener(this, Listener::VALUE_CHANGED); _startMax->addListener(this, Listener::VALUE_CHANGED); _endMin->addListener(this, Listener::VALUE_CHANGED); _endMax->addListener(this, Listener::VALUE_CHANGED); _energyMin->addListener(this, Listener::VALUE_CHANGED); _energyMax->addListener(this, Listener::VALUE_CHANGED); _emissionRate->addListener(this, Listener::VALUE_CHANGED); _started->addListener(this, Listener::VALUE_CHANGED); _reset->addListener(this, Listener::CLICK); _emit->addListener(this, Listener::CLICK); _zoomIn->addListener(this, Listener::PRESS); _zoomIn->addListener(this, Listener::RELEASE); _zoomOut->addListener(this, Listener::PRESS); _zoomOut->addListener(this, Listener::RELEASE); _save->addListener(this, Listener::RELEASE); _load->addListener(this, Listener::RELEASE); _burstSize->addListener(this, Listener::VALUE_CHANGED); _form->getControl("posX")->addListener(this, Listener::VALUE_CHANGED); _form->getControl("posY")->addListener(this, Listener::VALUE_CHANGED); _form->getControl("posZ")->addListener(this, Listener::VALUE_CHANGED); _posVarX->addListener(this, Listener::VALUE_CHANGED); _posVarY->addListener(this, Listener::VALUE_CHANGED); _posVarZ->addListener(this, Listener::VALUE_CHANGED); _velX->addListener(this, Listener::VALUE_CHANGED); _velY->addListener(this, Listener::VALUE_CHANGED); _velZ->addListener(this, Listener::VALUE_CHANGED); _velVarX->addListener(this, Listener::VALUE_CHANGED); _velVarY->addListener(this, Listener::VALUE_CHANGED); _velVarZ->addListener(this, Listener::VALUE_CHANGED); _accelX->addListener(this, Listener::VALUE_CHANGED); _accelY->addListener(this, Listener::VALUE_CHANGED); _accelZ->addListener(this, Listener::VALUE_CHANGED); _accelVarX->addListener(this, Listener::VALUE_CHANGED); _accelVarY->addListener(this, Listener::VALUE_CHANGED); _accelVarZ->addListener(this, Listener::VALUE_CHANGED); _spinSpeedMin->addListener(this, Listener::VALUE_CHANGED); _spinSpeedMax->addListener(this, Listener::VALUE_CHANGED); _axisX->addListener(this, Listener::VALUE_CHANGED); _axisY->addListener(this, Listener::VALUE_CHANGED); _axisZ->addListener(this, Listener::VALUE_CHANGED); _axisVarX->addListener(this, Listener::VALUE_CHANGED); _axisVarY->addListener(this, Listener::VALUE_CHANGED); _axisVarZ->addListener(this, Listener::VALUE_CHANGED); _rotationSpeedMin->addListener(this, Listener::VALUE_CHANGED); _rotationSpeedMax->addListener(this, Listener::VALUE_CHANGED); _vsync->addListener(this, Listener::VALUE_CHANGED); _form->getControl("sprite")->addListener(this, Listener::CLICK); _form->getControl("additive")->addListener(this, Listener::VALUE_CHANGED); _form->getControl("transparent")->addListener(this, Listener::VALUE_CHANGED); _form->getControl("multiply")->addListener(this, Listener::VALUE_CHANGED); _form->getControl("opaque")->addListener(this, Listener::VALUE_CHANGED); _form->getControl("updateFrames")->addListener(this, Listener::CLICK); // Load preset emitters. loadEmitters(); updateImageControl(); }