GameLight.Scene
GameLight.Graphics
- static void Rectangle(Image target, Color color, int x, int y, int width, int height)
- static void Text(Image target, int x, int y, string text, string fontName, double fontSize, Color color, FontStyle style)
GameLight.Input
GameLight.Sound
GameLight.Scene.GameControl
This is the playing surface. This control displays the game screen and requires input focus to work.
The game itself is started when StartingScene is set to a non-null value.
Constructor
GameControl()
Creates a GameControl instance. Although several properties require to be set before
the game starts, the default constructor exists to allow you to create the instance via XAML.
Properties
int GameHeight
The logical height of the game. This will determine the logical pixel size of the game screen, but
the control itself can be stretched to any size (or fullscreen'ed).
This property is required to be set the game is launched.
int GameWidth
The logical width of the game. This will determine the logical pixel size of the game screen, but
the control itself can be stretched to any size (or fullscreen'ed).
This property is required to be set the game is launched.
GameSceneBase StartingScene
This is the first game scene that the game will begin launching with.
The game will begin execution once the property has been set. once this has been set,
you cannot change it.
int TargetFramesPerSecond
The number of frames per second the game will try to maintain. The default is 60.
Key FullScreenShortcutKey
If set, pressing this key at anytime will set the game to be fullscreen. This key will, however, not exit fullscreen mode. You must press escape for that or make the game lose focus (alt-tab, etc.).
This is a GameLight.Input.Key, not a System.Windows.Input.Key.
void SetImageLoader(System.Windows.Controls.Image image)
In order for images to load, they must be part of the visual tree. In order for them to load
from the user assembly, they must be created in the user assembly. This is why you need to pass
in an Image control from outside the game.
This image must be part of the visual tree and can have visibility collapsed.
void SetSoundMixerHost(System.Windows.Controls.Grid emptySoundMixerContainer)
Similar to
SetImageLoader, in order for sounds to load
from the user assembly, they must be created in the user assembly. This is why you need to pass
in a grid from outside the game. This grid will be populated with MediaElements that will be used
to create sound and music effects during the game.
This Grid must be part of the visual tree and can have visibility collapsed.
GameLight.Scene.GameSceneBase
Classes implementing this base class are the heart of your game.
The implementations of Initialize, ProcessInput, Update, and Render methods
are automatically called repeatedly from the GameControl at the set framerate.
When you want switch to a different game scene state, pass a new
class implementing the GameSceneBase to the SwitchToScene method.
Properties
GameControl GameHost
A reference to the GameControl that hosts this GameScene.
SoundManager SoundManager
This is a reference to the sound manager. This is the entry point for functionality for playing sounds and music.
Music DefaultMusic
If not null, an implicit call to SoundManager.EnsureMusicPlaying will be called with this value.
Methods
abstract void Initialize()
This will be implicitly called by the GameHost before the first frame of this scene is run.
This call occurs after all images are loaded.
abstract void ProcessInput(InputEvent[] events)
This will be implicitly called by the GameHost at the beginning of the current frame.
The list of events are all events that occured between the end of the last ProcessInput call
and now.
abstract void Update(int gameCounter)
This will be implicitly called by the GameHost directly after ProcessInput.
The gameCounter is the frame number.
abstract void Render(Image gameScreen)
This will be implicitly called by the GameHost directly after Update.
This marks the end of the current frame.
The gameScreen is a Graphics.Image instance that can be modified. These modifications will
appear on the GameControl at the end of the frame.
void RequireImagesToPreload(params string[] images)
This method must be called with any images files you wish to use before you pass this GameScene instance
to the GameControl or SwitchToScene. These images will be loaded
asynchronously in a temporary loading scene. Once the images have been loaded, it will proceed to
this scene.
Images only need to be preloaded once during the lifetime of the game. After they have been loaded,
they can be used by any scene after that. If you wish, you can call this method with all the images
used in the game for the first scene and you don't have to call it again.
For information about creating a customized loading scene, see the tutorials page.
abstract void SwitchToScene(GameSceneBase nextScene)
The next frame will switch the given scene.
For information about creating transition scenes, see the tutorials page.
GameLight.Graphics.Image
Image instances store a 2-dimensional 32-bit image.
Constructors
Image(int width, int height)
Creates a new transparent image with the given pixel width and height
Image(int width, int height, int xOffset, int yOffset)
Creates a new transparent image with the given pixel width and height.
The provided X-offset and Y-offset are applied when this image is blitted onto another.
This is useful for sprite sequences where a large sequence of images of mostly the same size has one image that portrudes beyond the others.
A common example would be a character sprite swinging a sword. If the character's other images are 20 x 40 pixels, but the swinging sword adds
20 pixels to the left side of the character as a 40x40 image, it is ideal to logically treat the image as a 20x40 image with a -20 X-offset.
This reduces the need for extra bookkeeping in game logic as all images would be blitted at the same logical X and Y coordinates.
Image(Image image)
Creates a new image as an exact copy of the image passed in.
Image(string path)
Creates a new image from the given path. This can either be a relative path in the current assembly or a path
from a URL. Images instantiated in this fashion must be preloaded
first. This is because fetching an image from a server may be a costly and would drop the framerate when executed
as a blocking operation.
Properties
int Width
Pixel width of the image
int Height
Pixel height of the image
Methods
void Blit(Image source, int x, int y)
Copies the given source image to this image. The top left corner of the source image will appear at the given X and Y coordinates.
The exception to this is when the source image has a default X and Y offset. In that case, those will be added to the given x and y coordinates.
Colors are appropriately interpolated according to the alpha values of the pixels being blitted on one another.
void Fill(Color color)
Sets all the pixels to the given color
GameLight.Graphics.Draw
Static class containing helpful drawing functions. Currently functionality here is limited but more will be added soon.
Methods
void Rectangle(Image target, Color color, int x, int y, int width, int height)
Draws a rectangle of the given color, width, and height onto the target image with the top left corner positioned at the
given x and y coordinates.
void Text(Image target, int x, int y, string text, string fontName, double fontSize, Color color, FontStyle style)
Draws the given text onto the given image at the given x and y coordinates.
FontStyle enum:
- Normal
- Bold
- Italic
- BoldItalic
- Underline
- BoldUnderline
- ItalicUnderline
- BoldItalicUnderline
GameLight.Graphics.Color
Struct for storing a 24 or 32 bit color.
Constructors
Color(byte red, byte green, byte blue)
Creates an opaque color with the given RGB values.
Color(byte red, byte green, byte blue, byte alpha)
Creates a color with the given RGBA values.
GameLight.Graphics.Colors
Static class containing pre-defined colors.
- Black
- Blue
- Brown
- DarkBlue
- DarkGray
- Gray
- Green
- LightBlue
- LightGray
- Magenta
- Maroon
- Olive
- Orange
- Pink
- Purple
- Red
- Transparent
- White
- Yellow
GameLight.Input.InputManager
Static class that keeps track of which keys are pressed.
Methods
static bool IsKeyPressed(Key key)
Returns true or false whether or not the given key is pressed.
The Key enum here is a GameLight.Input.Key, not a System.Windows.Input.Key.
The GameLight.Input.Key enum contains many keys that are not defined in the System enum.
GameLight.Input.InputEvent
A GameLight-specific input event. The system event in Silverilght has a few shortcomings when used
in the context of a game. For example, mouse coordinates are doubles and require a UI Element as a
frame of reference. The X and Y coordinates are logical game screen coordinates regardless of how
the game surface is stretched.
Properties
EventType Type
The type of this event. Could be KeyDown, KeyUp, MouseDown, MouseUp, MouseEnter, MouseLeave, or MouseMove.
MouseButton Button
If this is a MouseDown or MouseUp event, this defines which mouse button it pertains to.
Key Key
If this is a KeyDown or KeyUp event, this returns the key it pertains to.
The Key enum here is a GameLight.Input.Key, not a System.Windows.Input.Key.
The GameLight.Input.Key enum contains many keys that are not defined in the System enum.
int X
If this is a Mouse event, this returns the X coordinate where the event occured.
This coordinate is in reference to the game's logical coordinates, not the coordinate in the view (so that you get the same value whether the game is full screen or not).
int Y
If this is a Mouse event, this returns the Y coordinate where the event occured.
This coordinate is in reference to the game's logical coordinates, not the coordinate in the view (so that you get the same value whether the game is full screen or not).
GameLight.Input.EventType
Enum containing the various kinds of events supported.
- MouseDown
- MouseUp
- MouseMove
- MouseLeave
- MouseEnter
- KeyDown
- KeyUp
GameLight.Input.Key
Enum containing the all the possibly definable keys.
This enum contains many more values that the System.Windows.Input.Key enum does not.
Values not present in the System enum are highlighted in blue.
- None
- Unknown
- A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z
- Num0, Num1, Num2, Num3, Num4, Num5, Num6, Num7, Num8, Num9
- NumPad0, NumPad1, NumPad2, NumPad3, NumPad4, NumPad5, NumPad6, NumPad7, NumPad8, NumPad9
- F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12
- Up, Down, Left, Right
- Enter
- Escape
- Space
- Tab
- Shift - Unfortunately Silverlight makes no distinction between left and right shift and control the way .NET does.
- Control
- Backspace
- Semicolon
- Equals
- Comma
- Hyphen
- Period
- Slash
- Tilde
- BracketOpen
- BracketClose
- Backslash
- Apostrophe
- Home
- End
- Insert
- Delete
- PageUp
- PageDown
- Break
- NumLock
- ScrollLock
- PrintScreen
- WindowsKey - Note: On Macs this will apply to the clover key
- InvokeContextMenu
- KeyboardMuteButton
- KeyboardVolumeDownButton
- KeyboardVolumeUpButton
- KeyboardMusicStopButton
- KeyboardMusicPlayPauseButton
GameLight.Input.MouseButton
Enum containing the mouse buttons.
GameLight.Sound.SoundManager
A sound manager reference is automatically stored in all GameSceneBase instances right before they
are initialized. This class exposes functionality for playing sounds and music.
Methods
void PlayMusic(Music music)
Plays the given music. The exit transition of the previous song is defined in the Music class. If you
wish to stop or transition out the current playback, pass in a Sound.Music instance that contains a
null for the music path.
void EnsureMusicPlaying(Music music)
This is mostly identical to PlayMusic. If the current music matches the the Music instance passed in,
no action will occur.
void PlaySound(Sound sound)
Plays the given sound. A maximum of 16 sounds can be played simultaneously without any getting
stopped before playback finishes.
GameLight.Sound.Sound
This is an instance of a sound that can be played by the SoundManager.
Constructor
Sound(string path)
Creates a sound instance of the sound located at the given path.
A path is either relative to a local assembly resource or an absolute path for web content.
GameLight.Sound.Music
This is an instance of a sound that can be played by the SoundManager as music and contains information about transitions to this music and the currently playing music.
Constructor
Music(string path)
Creates a music instance of the sound located at the given path.
A path is either relative to a local assembly resource or an absolute path for web content.
By default, this music will stop the current playback, play once, and play at standard volume.
These can be overriden by the various properties.
Properties
MusicLoopStyle Loop
Sets the Loop style with the MusicLoopStyle enum:
double NormalizationFactor
A factor between 0.0 and 2.0 that will scale the default volume for this music.
MusicTransitionStyle Transition
Sets the entrance transition of this song and the exit transition of the song currently playing if there is one.
These are defined by the MusicTransitionStyle enum:
- Instant - will stop the current music and play this one
- FadeOutCurrentAndPlay - will fade out the current music and play this one
- FadeOutCurrentAndStop - will fade out the current music and stop
- FadeoutCurrentFadeInThisSimultaneously - will fade out the current music while fading this one in at the same time
double TransitionSeconds
Sets the duration of the transition defined by the Transition property. The unit for this property is seconds.