Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
SetFullScreen sets the game to run in full screen. This function can change the current resolution of the desktop. Graphics cards only support a certain number of resolution configurations. If SetFullScreen is called with a value not supported by the graphics device, an exception will be thrown.
The following code sets the game to run in full screen, using the current display resolution.
The IsFullScreen property can be set to make your game run in full screen mode or windowed mode. Keep in mind that only certain resolutions are supported in full screen, so you should make sure that your desired resolution is supported before setting full screen to avoid crashes.
The SizeOrOrientationChanged event is an event which is raised whenever the resolution of the screen is changed, or if the orientation changes. This allows your game to react to the resolution change as necessary. For example, Windows 8 applications can be docked, and when this occurs the screen space for the application changes. This event is not raised when a Windows Desktop app's restore button is clicked (after being maximized), so Windows Desktop apps should use the
In this example you may detect if the user has docked the game, and if the aspect ratio is smaller than some value (indicating that the dock is narrow), then you may want to pause the game.
The GraphicsOptions class provides high-level control over the graphical presentation of FlatRedBall. As a user you do not need to create an instance of GraphicsOptions, it is done automatically when the engine is created. It is exposed through the FlatRedBallServices class. However, you can explicitly instantiate a GraphicsOptions to make changes prior to the initialization of FlatRedBall. This is useful for setting resolution or fixing compatibility issues. Of course, if this is done you need to suspend and resume the device resets, as explained below.
Whenever a property is changed on the GraphicsOptions, the FlatRedBall Engine attempts to implement the changes immediately. However, this can cause problems when properties are changed on a GraphicsOptions instance prior to the initialization of FlatRedBall. If this occurs, the graphics device is not yet created so the setting of the property will raise an exception. This exception can be avoided by suspending device resets. If device resetting is suspended then the properties of a GraphicsOptions instance will be updated, but the device will not be reset. If the changed instance is then used to initialize FlatRedBall then the changed properties will be applied to the graphics device when it is first created. The following code tells the engine to initialize the engine in full-screen:
Filtering is a process to reduce the pixellated look of textures when viewed from up close. Without filtering, each pixel represents a rectangular area of a solid color on a Sprite. For example, the following image shows the redball.bmp graphic without filtering. Here is a black and white checkered image. It has been enlarged so that the checkered image is clearly visible: With filtering, each pixel represents a color at just one point. When a texture is displayed on the screen, the color for each pixel on the screen is determined through an interpolation between the nearest pixels. The following image shows the redball.bmp graphic with filtering. Here is another example of how filtering affects a 16X16 black and white checkered image (again, enlarged to show detail): Filtering not only "blurs" the color of each pixel from the source image, but also the transparency. Therefore, rather than having a solid edge, the edge pixels will gradient to transparency. Filtering can be a beneficial technique for reducing visible pixels, but can cause problems as explained in the following section.
For more information on how to enable and disable Filtering in your FlatRedBall project, see: GraphicsOption's Filtering property
Although Filtering can greatly improve the appearance of a Sprite, it can also cause problems. Consider the following situation. You are interested in creating a white sphere. You create a .png with the center white and fully opaque and the borders transparent. In your image editing program, everything looks great. However, when you load the white sphere in the SpriteEditor or other FlatRedBall application with filtering turned on, you notice a dark border around your white Sprite. The following image shows some simple colored shapes with a dark filtering halo over a white background. The reason this occurs is because the color of the transparent pixels are "averaged" or interpolated at points which display the Sprite. That is, the edge point on a Sprite may have an RGB value of (255,255,255) - white. Its alpha may also be 255 - fully opaque. Its neighboring pixel may have an alpha of 0 - fully transparent. However, its color value still exists. In the image shown above, the transparent pixels have an RGB value of (0,0,0) - black. Therefore, any point that is "between" the fully transparent and fully opaque pixels will have an averaged color. That is, the point on the screen which is halfway between the opaque and transparent pixel will have an alpha value of around 127 - half transparent; however, its color value will be the average of (0,0,0) and (255, 255, 255) which is around (127, 127, 127) - gray. This is often a problem which arises when games use transparent pixels and filtering. This can be solved manually by coloring the transparent pixels the same color as any opaque pixels. For example, consider the white ball presented previously. To solve the filtering halo, all transparent pixels should be white. After the change, the only difference between the transparent pixels and the white pixels should be the alpha value.
Kao Martin provided a wonderful tool for removing filtering halo from files. It can be found here.
An excellent feature of The GIMP is that the eyedropper tool gives you both the color of the current pixel considering alpha and also ignoring trancparency. This allows you to easily see the color of pixels which are transparent and helps identify problems related to halo filtering. To fix the filtering, first, identify the location which is causing problems using the eyedropper. Once you have spotted a point where a fully transparent pixel is touching a fully opaque pixel but their colors do not match, use the eyedropper to select the color of the neighboring opaque pixel. Next, simply paint the transparent pixel the color of the opaque pixel - this will make the transparent pixel opaque. Finally, erase the newly-painted pixel so that it is transparent once again. Notice that if you select the pixel with the eyedropper, the color matches the opaque pixel. One way to do this a little faster is to use the "Fuzzy Select" (also known as the magic wand in Photoshop) to select the transparent area and paint multiple pixels at once without modifying the transparent pixels.
The SetResolution method sets the resolution (number of pixels wide and tall) of your game. This method can be called at any time after FlatRedBall is initialized.
The following code resizes the screen to display a resolution of 320X240.
Resolutions can be changed by calling SetResolution multiple times. For example, the following code allows the user to press the 1 or 2 keys to change between two resolutions:
By default if SetResolution is called, the Camera will adjust its DestinationRectangle according to the changed resolution. This automatic adjustment depends on the Camera's split screen viewport settings. For more information, see the SetSplitScreenViewport page.
One common piece of code that people use (incorrectly) to set the game resolution to the entire display's resolution is:
While this may seem fine, let's investigate what happens. The SetResolution method sets the resolution to the monitor's width/height; however, it can't actually set it to the full height. The reason for this is because Windows prevents the game window from being much taller than your current resolution. In other words, Windows resizes your game window's height to allow for the title bar and window borders. Here's a screen shot from Visual Studio showing the variables being different: Notice that the code above sets the resolution to the GraphicsDevice.DisplayMode.Height which clearly shows up as 768 on my monitor; however, the FlatRedBallServices.GraphicsOptions.ResolutionHeight (stored in a height variable) is only 752. The moral of the story is - when in windowed mode, don't set your resolution to the monitor's full-screen resolution.
The ResolutionWidth and ResolutionHeight members can be used to get and set the resolution of the game. If you are setting both ResolutionWidth and ResolutionHeight, consider using SetResolution instead of setting each value independently to avoid a double-resize.
Filtering is the process of modifying how a texture is drawn to reduce the effect of pixellation when viewing a texture at a large size on screen.
If you are using the FlatRedBall Editor, then the default TextureFilter depends on the setting in the Display Settings. If you are using pure code, then the default is Linear.
The GraphicsOptions.TextureFilter property can be used to control the default project-wide texture filter. Individual Sprites can overwrite this value. For more information, see the Sprite TextureFilter page.
Filtering can be controlled through the GraphicsOptions class. The following code creates a large Sprite which takes up the entire screen. Pressing the space key toggles the filtering between Linear (on) and Point (off).
Add the following to Update:
TextureFilter.Linear:
TextureFilter.Point:
If you are using tile maps (such as loading a .tmx file) then you will most likely need to set the texture filter to point. Otherwise you may see lines between your tiles:
The GraphicsOptions' TextureLoadingColorKey allows you to set the color to ignore when loading .bmp graphics. The TextureLoadingColorKey value is only applied to .bmp images and not to other images. The reason for this is because other image formats either:
Have lossy compression so exact colors are not preserved and color keys are not an effective way to create transparency.
Include an alpha channel which include the ability to have partial transparency.
The following code creates a Sprite from a graphic which has a magenta background. The bool ifUsingColorKey controls whether the color key is set to Magenta or not - the default color is Black. Files used: Add the following to Initialize after initializing FlatRedBall:
Setting the ifUsingColorKey to false will result in a magenta box being drawn around the redball graphic.
You may be wondering why the above tutorial requires a recompile and a change of the bool instead of simply creating two Sprites with a change in the TextureLoadingColorKey between the creation of the two Sprites. The reason for this is because FlatRedBallServices caches. Therefore an actual load is only performed the first time that the redball.bmp graphic is referenced. Every subsequent time, the texture reference to the cached texture data is returned. The exception to this is if different content managers are used.