3. Example Projects
Here are two more simple conversions of
Windows Phone 7 Silverlight examples that we created earlier. Neither of
these has had any presentation attention lavished upon them, so they
look extremely basic, but they demonstrate the direct conversion results
that are achieved when converting into the browser-based Silverlight
environment.
3.1. Navigation
The Navigation project demonstrates how navigation within a Frame
control works when running in the browser. When you launch the project,
the simple game framework menu will appear just as it did on the phone.
Clicking the buttons will navigate between the different pages.
Note that each time you click a button, the browser's
navigation history is updated. This allows you to use the browser's
Back button to return to the previous page, just like on the phone. Also
observe that the stack is manipulated in exactly the same way as on the
phone when navigating between non-menu pages; click the End Game button
in the "Game" page and you will be sent to the "High scores" page, but
clicking Back here returns you to the menu, not to the "Game" page.
Also note that state is maintained between the pages
in exactly the same way as on the phone. If you click the Back button
from the game page, the menu offers the Resume Game button, and clicking
it will return you to the game. The state is maintained despite the
browser navigation that is taking place.
If you click to start a new game while an existing game is active, you will notice that the MessageBox call works perfectly well in the browser-based Silverlight, too.
In practice, including navigation in a game that you
are converting to the browser might be more than you really need,
especially if you simply want to give the player an idea of what the
game has to offer. It might be more sensible to launch straight into the
game and not worry about including the overheads of high score tables
and so on. Once you have convinced the players that your game is worth
further investigation, they can take advantage of all these features in
the full version on the phone.
Apart from the changes described for converting
project pages from the Windows Phone 7 Silverlight environment into the
browser environment, there are no code changes to this project at all.
3.2. Diamond Lines
As you will see if you open and launch the project,
it performs very nicely in the browser. The higher specification of a PC
results in a very smooth experience. The storyboard animation really
helps as it allows the graphics to move as quickly as the PC can animate
them, but still ensure that they move at the correct speed, resulting
in predictable and very smooth animation.
Figure 5 shows a screenshot of the game running inside Mozilla Firefox.
Once again, the changes required to get this running
were no more than described for converting pages earlier on. Despite the
game using just a single page (MainPage, in which the game is displayed) we still use the HostPage
approach here, both because it simplifies the import of the existing
page and because it allows us to more easily add in navigation support
later should we want to.