Silverlight Viewports
Posted on November 14, 2007
Filed Under: 1.1 Alpha, Components, Games, User Interface |
One thing you usually recognize about web-based games is that they generally have a fixed view. With a fixed view, your game world matches the web control 1:1. What if you want the game to take place in a larger space, like an entire world, or a galaxy. In the game world, you’d create a viewport or a camera that only displays a portion of the world. Unfortunately, Silverlight doesn’t have native support for viewports into a larger space. We decided to make it.
Source: CanvasViewport C# class
The CanvasViewport is a simple plugin class that can be used to create a viewport on any Canvas (it doesn’t have to be the main page). It works by manipulating the Canvas’ RenderTransform in response to programmed parameters.
Usage:
// Create a viewport on this canvas.
CanvasViewport _Viewport = new CanvasViewport(this);
// Create a viewport that is 320x240 in logical (original canvas) units
_Viewport.Size = new Size(320, 240);
// Set the center of this viewport to 500, 800 on the canvas
_Viewport.Center = new Point(500, 800);
// In a game, you can have the viewport track a player like this:
void Update()
{
_Player.Update();
_Viewport.Center = _Player.Position;
}
An added advantage to using viewports in XAML is that since XAML graphics are all vector based, zooming in and out dosen’t have all of the pixelation problems that working with raster graphics has. Here’s the orignal game without the viewport.
Here’s the game with a smaller viewport into the original world. (Notice that the UI and the Reticle doesn’t change size).

Have fun with your viewports.
Comments
Leave a Comment
If you would like to make a comment, please fill out the form below.
Recently
- New Vectorform Blog - Microsoft Surface
- Now Hiring Silverlight Developer
- Silverlight Streaming for video assets only
- Silverlight Streaming Service
- Compressing XAML to save on file size
- Controlling Silverlight outside of the plugin - the .Content property
- Accessing the canvas in a Silverlight 1.1 User Control
- Happy Silverlight Holidays from Vectorform
- Silverlight Shooter nears completion
- Microsoft Surface Animation - The making of “Infinite Possibilities”
Categories
- 1.0 Javascript
- 1.1 Alpha
- Animation
- Application
- Career Opportunities
- Components
- Design
- Games
- News
- streaming
- Team Members
- Uncategorized
- User Interface
- video
- Web Service
- XAML
Archives
- August 2008
- June 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
