User Tools

Site Tools


en:guides:beginners:viewport_and_camera

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:guides:beginners:viewport_and_camera [2018/06/27 12:21 (7 years ago)] sausageen:guides:beginners:viewport_and_camera [2025/09/30 17:26 (12 days ago)] (current) – external edit 127.0.0.1
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 MyGame.ini and you'll see that a ''[Viewport]'' section has already been specified for you.+Take a look at your MyGame.ini and you'll see that a ''[MainViewport]'' section has already been specified for you.
  
 <code=ini> <code=ini>
-[Viewport]+[MainViewport]
 Camera             = MainCamera Camera             = MainCamera
 </code> </code>
Line 14: Line 14:
 Let's give our game a blue sky as a background, by adding the ''BackgroundColor'' property to the config: Let's give our game a blue sky as a background, by adding the ''BackgroundColor'' property to the config:
  
-<code=ini> +<code=ini [highlight_lines_extra="3"]
-[Viewport]+[MainViewport]
 Camera            = MainCamera Camera            = MainCamera
 BackgroundColor   = (0, 180, 255) BackgroundColor   = (0, 180, 255)
Line 35: Line 35:
 Let's change the screen width and height so that it makes working through the tutorial easier (and easier to take screenshots :) ): Let's change the screen width and height so that it makes working through the tutorial easier (and easier to take screenshots :) ):
  
-<code=ini>+<code=ini [highlight_lines_extra="2,3"]>
 [MainCamera] [MainCamera]
 FrustumWidth    = 800 FrustumWidth    = 800
Line 44: Line 44:
 </code> </code>
  
-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 ''ScreenWidth'' and ''ScreenHeight'' values from the ''[Display]'' section are being inherited from the ''FrustumWidth'' and ''FrustumHeight'' values, as you can see at:+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 ''ScreenWidth'' and ''ScreenHeight'' values can be added to the ''[Display]'' section and are being inherited from the ''FrustumWidth'' and ''FrustumHeight'' values:
  
 <code ini> <code ini>
Line 53: Line 53:
 </code> </code>
  
-The viewport needs to be created when our game runs, so let's take a look at the MyGame.cpp code:+The viewport needs to be created when our game runs, so let's take a look at the MyGame.code (for a C++ project, look for ''MyGame::Init'' in MyGame.cpp):
  
-<code=cpp>+<code=c>
 orxSTATUS orxFASTCALL Init() orxSTATUS orxFASTCALL Init()
 { {
  
-    orxViewport_CreateFromConfig("Viewport");+... 
 +  orxConfig_PushSection("Main"); 
 + 
 +  for(orxS32 i = 0, iCount = orxConfig_GetListCount("ViewportList"); i < iCount; i++) 
 +  { 
 +    orxViewport_CreateFromConfig(orxConfig_GetListString("ViewportList", i)); 
 +  } 
 </code> </code>
  
-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.+Here the ''"ViewportList"'' refers to this section of the config file: 
 +<code ini> 
 +[Main] 
 +ViewportList    = MainViewport 
 +</code>
  
 +You could also called ''orxViewport_CreateFromConfig'' on a static name:
 +<code=c>
 +orxSTATUS orxFASTCALL Init()
 +{
  
-The "Viewportstring parameter specified in that function is the same name as the ''[Viewport]'' section in the config.+... 
 +   
 +    orxViewport_CreateFromConfig("MainViewport");
  
-Because the camera was specified in the ''[Viewport]'' section, we do not need to create a camera in code.+</code>
  
-Final thing for this step is to name our game. This name will show in the window titleSet this with the ''Title'' property in the ''[Display]'' section. Also while you are here, set the ''Smoothing'' to false:+The Init() function runs once when your game first executes, and this is where the viewport is created.
  
-<code=ini>+The "MainViewport" string parameter specified in that function is the same name as the ''[MainViewport]'' section in the config. 
 + 
 +Because the camera was specified in the ''[MainViewport]'' section, we do not need to create a camera in code. 
 + 
 +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. Also while you are here, set the ''Smoothing'' to false, and Decoration to true which means to make a standard window: 
 + 
 +<code=ini [highlight_lines_extra="4,6,7"]>
 [Display] [Display]
 ScreenWidth     = @MainCamera.FrustumWidth ScreenWidth     = @MainCamera.FrustumWidth
Line 77: Line 100:
 Title           = Platform Hero Title           = Platform Hero
 FullScreen      = false FullScreen      = false
 +Decoration      = true
 Smoothing       = false Smoothing       = false
 VSync           = true VSync           = true
Line 86: Line 110:
 [Display] [Display]
 Title           = Platform Hero (Debug) Title           = Platform Hero (Debug)
-ShowFPS         = true 
 </code> </code>
  
en/guides/beginners/viewport_and_camera.1530102099.txt.gz · Last modified: 2025/09/30 17:26 (12 days ago) (external edit)