Пример #1
0
    void MainGame::Start()
    {
        // Setup State Manager
        context_->RegisterSubsystem(new blu::StateManager(context_));
        
        auto input = context_->GetSubsystem<Urho3D::Input>();

        // Set mouse cursor to be visible
        input->SetMouseVisible(true);
        
        // Set state
        context_->GetSubsystem<blu::StateManager>()->SetState(new Game::GameState(context_));
        //context_->GetSubsystem<blu::StateManager>()->SetState(new Menu::MenuState(context_));
        //context_->GetSubsystem<blu::StateManager>()->SetState(new Intro::Intro(context_));
    }
Пример #2
0
/** Support objects created, start application specific content. */
void UApp::Start() {
    // the mouse must be in cursor mode before setting the UI.
    auto input_ = GetSubsystem< Urho3D::Input >();
    input_->SetMouseVisible(true);

    // resources origin.
    cache_ = GetSubsystem< Urho3D::ResourceCache >();

    // use the default style from Urho3D.
    GetSubsystem< Urho3D::UI >()->GetRoot()->SetDefaultStyle(
                cache_->GetResource< Urho3D::XMLFile >("UI/DefaultStyle.xml"));

    // grab mouse
    input_->SetMouseGrabbed(true);

    // setup scene to render.
    scene_ = new Urho3D::Scene(context_);
    scene_->CreateComponent< Urho3D::Octree >();

    // Create the light
    {
        auto lightNode = scene_->CreateChild("Light");
        lightNode->SetPosition(Urho3D::Vector3(6, 6, -20));
        auto light = lightNode->CreateComponent< Urho3D::Light >();
        light->SetLightType(Urho3D::LIGHT_POINT);
        light->SetRange(1000);
    }

    // setup camera
    {
        auto cameraNode_ = scene_->CreateChild("Camera");
        cameraNode_->SetPosition(Urho3D::Vector3(6, 6, -20));
        auto camera_ = cameraNode_->CreateComponent< Urho3D::Camera >();
        camera_->SetFarClip(2000);
        auto renderer = GetSubsystem< Urho3D::Renderer >();
        Urho3D::SharedPtr< Urho3D::Viewport > viewport(new Urho3D::Viewport(context_, scene_, camera_));
        renderer->SetViewport(0, viewport);
    }

    // start the game
    game.start();

    // subscribe to events
    SubscribeToEvent(Urho3D::E_UPDATE,URHO3D_HANDLER(UApp,HandleUpdate));
    SubscribeToEvent(Urho3D::E_KEYDOWN,URHO3D_HANDLER(UApp,HandleKeyDown));
    SubscribeToEvent(Urho3D::E_KEYUP,URHO3D_HANDLER(UApp,HandleKeyUp));
}