This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:guides:beginners:viewport_and_camera [2018/02/13 20:47 (7 years ago)] – ↷ Page moved from guides:beginners:viewport_and_camera to en:guides:beginners:viewport_and_camera iarwain | en:guides:beginners:viewport_and_camera [2024/11/17 02:31 (5 months ago)] (current) – Fixes and alignment to newer orx. sausage | ||
---|---|---|---|
Line 5: | 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 |
</ | </ | ||
- | Change | + | The '' |
- | < | + | Let's change the screen width and height so that it makes working through the tutorial easier (and easier to take screenshots :) ): |
- | [Camera] | + | |
- | FrustumWidth | + | < |
- | FrustumHeight = @Display.ScreenHeight | + | [MainCamera] |
- | FrustumFar | + | FrustumWidth |
- | FrustumNear | + | FrustumHeight |
- | Position | + | FrustumFar |
+ | FrustumNear | ||
+ | Position | ||
</ | </ | ||
- | The camera is positioned into the center of the screen | + | A frustum width and height does not have to be the same size as your screen, |
- | 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 values are being inherited from the ScreenWidth and ScreenHeight parameters in the [Display] | + | <code ini> |
+ | [Display] | ||
+ | ScreenWidth | ||
+ | ScreenHeight | ||
+ | ... | ||
+ | </ | ||
- | The viewport needs to be created when our game runs, so let's take a look at the Project.cpp code: | + | The viewport needs to be created when our game runs, so let's take a look at the MyGame.cpp code: |
< | < | ||
Line 57: | Line 59: | ||
{ | { | ||
- | orxViewport_CreateFromConfig(" | + | orxViewport_CreateFromConfig(" |
</ | </ | ||
Line 63: | Line 65: | ||
- | The "Viewport" parameter specified in that function is the same name as the [Viewport] section in the config. | + | The "MainViewport" |
- | Because the camera was specified in the [Viewport] section, we do not need to create a camera in code. | + | Because the camera was specified in the '' |
- | 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 '' |
- | < | + | <code=ini [highlight_lines_extra=" |
+ | [Display] | ||
+ | ScreenWidth | ||
+ | ScreenHeight | ||
+ | Title = Platform Hero | ||
+ | FullScreen | ||
+ | Decoration | ||
+ | Smoothing | ||
+ | VSync = true | ||
+ | </ | ||
+ | |||
+ | This will change the name in the window title, but only if you are compiling in Release mode. You'll most likely be compiling in Debug mode right now. So you'll also need to change the title in the '' | ||
+ | |||
+ | < | ||
[Display] | [Display] | ||
- | ScreenWidth | + | Title |
- | ScreenHeight | + | |
- | Title | + | |
</ | </ | ||
- | Compile and run to see your game window with a blue background and a default object in the top left of the screen. This because of the position of the camera, and that the default object is at position (0,0) by default: | + | Compile and run to see your game window with a blue background and a default object in the center |
{{: | {{: | ||
Line 82: | Line 95: | ||
---- | ---- | ||
- | Next: [[guides: | + | Next: [[en:guides: |
- | {{section> | + | {{section> |