This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
guides:beginners:viewport_and_camera [2015/10/24 18:37 (9 years ago)] – sausage | en:guides:beginners:viewport_and_camera [2020/08/19 12:15 (4 years ago)] (current) – Viewport -> MainViewport to match the changes in init's template iarwain | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Part 5 – Viewport and Camera ====== | ====== Part 5 – Viewport and Camera ====== | ||
- | |||
- | From here on, I'll assume that you performed step 4, and that your project is called " | ||
In order for anything to appear in your game, you will first need both a viewport and a camera. | In order for anything to appear in your game, you will first need both a viewport and a camera. | ||
Line 7: | Line 5: | ||
A viewport is the rectangle that we can view the game world through. And a camera allows us to see all or part of that world at a time. | A viewport is the rectangle that we can view the game world through. And a camera allows us to see all or part of that world at a time. | ||
- | Take a look at your Project.ini and you'll see that a [Viewport] section has already been specified for you. There are some commented out options like Size and BackgroundColor: | + | Take a look at your MyGame.ini and you'll see that a '' |
< | < | ||
- | [Viewport] | + | [MainViewport] |
- | Camera | + | Camera |
- | ; | + | |
- | ; | + | |
- | ; | + | |
- | ;Size = (200, 150, 0) NB: Size is in pixels and will be ignored if RelativeSize is specified | + | |
- | ; | + | |
</ | </ | ||
- | Our game will have a blue sky as a background, | + | Let's give our game a blue sky as a background, |
< | < | ||
- | [Viewport] | + | [MainViewport] |
- | Camera | + | Camera |
BackgroundColor | BackgroundColor | ||
</ | </ | ||
- | Secondly, notice the Camera parameter is set to Camera? This means it is set to the [Camera] section, which has also already been defined for you: | + | Secondly, notice the Camera parameter is set to '' |
< | < | ||
- | [Camera] | + | [MainCamera] |
- | FrustumWidth | + | FrustumWidth |
- | FrustumHeight = @Display.ScreenHeight | + | FrustumHeight |
- | FrustumFar | + | FrustumFar |
- | FrustumNear | + | FrustumNear |
- | Position | + | Position |
</ | </ | ||
- | The camera | + | The '' |
- | A frustum width and height does not have to be the same size as your screen, but for our game, we want it to be. So the width and height | + | Let's change |
- | The viewport needs to be created when our game runs, so let's take a look at the Project.cpp code: | + | < |
+ | [MainCamera] | ||
+ | FrustumWidth | ||
+ | FrustumHeight | ||
+ | FrustumFar | ||
+ | FrustumNear | ||
+ | Position | ||
+ | </ | ||
+ | |||
+ | A frustum width and height does not have to be the same size as your screen, but for our game, we want it to be. So the '' | ||
+ | |||
+ | <code ini> | ||
+ | [Display] | ||
+ | ScreenWidth | ||
+ | ScreenHeight | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | The viewport needs to be created when our game runs, so let's take a look at the MyGame.cpp code: | ||
< | < | ||
Line 48: | Line 59: | ||
{ | { | ||
- | orxViewport_CreateFromConfig(" | + | orxViewport_CreateFromConfig(" |
</ | </ | ||
- | Nice and simple. Our project already has this added. The init() function runs once when your game first executes, and this is where the viewport is created. | + | Nice and simple. Our project already has this added. The Init() function runs once when your game first executes, and this is where the viewport is created. |
- | The "Viewport" parameter specified in that function is the same name as the [Viewport] section in the config. | + | The "MainViewport" |
- | Now, because | + | Because |
- | Final thing for this step is to name our game. This name will show in the window title. Set this with the Title property in the [Display] section: | + | Final thing for this step is to name our game. This name will show in the window title. Set this with the '' |
< | < | ||
[Display] | [Display] | ||
- | ScreenWidth | + | ScreenWidth |
- | ScreenHeight | + | ScreenHeight |
- | Title | + | Title |
+ | FullScreen | ||
+ | Smoothing | ||
+ | VSync = true | ||
</ | </ | ||
- | Compile and run to see your game window | + | This will change the name in the window |
- | {{: | + | <code ini> |
+ | [Display] | ||
+ | Title = Platform Hero (Debug) | ||
+ | ShowFPS | ||
+ | </ | ||
+ | |||
+ | Compile and run to see your game window with a blue background and a default object in the center of the screen: | ||
+ | |||
+ | {{: | ||
---- | ---- | ||
- | Next: [[guides: | + | Next: [[en:guides: |
+ | |||
+ | {{section> |