Silverlight Tutorial by Billy

Total Page:16

File Type:pdf, Size:1020Kb

Silverlight Tutorial by Billy

Silverlight Tutorial by Billy Most of the information to make the conversion is shown here: http://silversprite.codeplex.com/

However it can be hard to understand if you are not used to silverlight, so I'll try to explain it.

First Off:  Silversprite is meant for xna 3.1 and some upper level functionality may not be there, however for our purposes and the knowledge of the 1302 students show limit this problem.  XNA networking does not work  XACT sound does not work  PNG, JPG or BMP seem to be the only working image types  mp3 and wma seem to be the only working sound types  If you are using XNA 4.0 in order to send your content to silverlight you have to make a folder called "Content" and place all the content under that colder making sure EVERYTHING in that folder you plan to use for the load content will be under the build option of "Content", in 4.0 this is not always the default.  Any sort of file I/O will need to be under build content of "Resource" (This might be old information so it might change if someone is planning on using it--will update once we find the correct info) o Note: there will be some code changes needed for this since you will be switching from directory type to isolated storage (This is due to the fact that it is running in a browser)  NEW!!!: Under Project->Project Properties->Silverlight tab->Silverlight build options->ENABLE RUNNING APPLICATION OUT OF BROWSER, if this is checked it will allow you to fully debug your game!! Frequent Issues:  All i see is the color that i clear the graphics device to! o This generally means that you are missing some content, which could mean that its not there or the build actions were not set properly  The application never loads! o Make sure your XAML is correct.  All I see is white! o Some errors will not be caught by the debugger, Try going through one game loop on a set-by-step basis and you should find the error.  My question remains unanswered!! o Come see me! (Billy) Creating a silverlight application: In Visual Studio 2010 you select New->Project->Silverlight application (fill in the information)- >Next make it so the next screen looks like this:

Then hit OK.

You should then see a blank XAML form in front of you, showing that the creation was sucessful.

In the solution explorer you should see the project you just created, This is where you will add all your game classes (except Program.cs). Once that is done Create the "Content" folder and place your content in it while maintaining the file structure. Here is my example from making a quick grid game for my AI class and then porting it to silverlight: In this picture all three solutions are in the same project, this is not needed. As you can see the 2 classes that make up the game are "Game1.cs" and "AINode.cs" and were just copy-pasted to the silverlight project. the content was moved from the content project into the "Content" folder (which was created by me) and the build action set to "Content", again if you are loading things in (txt files) you will need to set the build action to "Resource" and the "Output to content directory" as "Copy if newer".

Once that is done you need to make some changes to the XAML of the main page:

The only things you have to add are in blue and red. The canvas can be dragged and dropped in from the toolbox but the blue will need to be added in manually. The namespace is the namespace of your "Game1.cs" and the game tag will consist of the class that starts the game, in my case it is called "Game1". Once that is done you should be able to run the game in your browser!!!

Recommended publications