This project is read-only.

How to load content?

Mar 27, 2009 at 5:37 PM

Hi Bill,

I'm interested in seeing if I can get my 2D XNA project to run with SilverSprite.  I've gone through all the steps listed so far and have had to refactor a fair amount of code (for things like xml serialisation from an isolated storage).  

I've hit a brick wall at loading the .xnb files.  You mention to add the .xnb as content to the project, but when I get to the following line I get a ContentLoadException, 'File could not be opened':

font = content.Load<

SpriteFont>("Art/Fonts/" + "default_menu");

I've been able to deserialize by game data content, so I'm pretty sure that I've got the file locations set up correctly.  Any pointers on where I'm going wrong?

Thanks,
C

 

Mar 27, 2009 at 7:33 PM
Thanks for your post. First of all, XML serialization can work, you need to include another Silverlight library, System.Xml.Serialization, and then that should work. For file access from Isolated Storage, I provide an implementaion of the File class, it's in namespace SilverXna.IO (looks like I never renamed this, I'll have to), so you may be able to keep most of your file handling code in place, and just add a SilverXna.IO prefix to your File declarations, it depends on what exactly you are doing, but it works for the Marblets sample and also for Dr. Popper, so this might let you keep the code more consistent with your XNA version.

Now for the Content issue. The could very well be a bug here, so I'll explain how it works now and if maybe the file is in the wrong place. If it's not, hopefully I can get some more information from you. There are two options for where it will look.

If the ContentManager's RootDirectory is the empty string, your above code would look in Art/Fonts/default_menu.spriteFont and if that doesn't exist it will look for Art/Fonts/default_menu.xnb

If the ContentManager's root directory is something else, let's use Content for this example, then this is appended to the front of the path and it would be Content/Art/Fonts/default_menu.xnb or .spriteFont

Typically the RootDirectory is set in your Game's constructor.

So if everything still looks right and it's not working, please reply and I'll investigate further.

Bill
Mar 28, 2009 at 6:44 PM
Thanks Bill, that was very useful - I'd completely missed SilverXna.IO.  The problem was that I'd overriden ContentManager with my own version to handle encrypted assets.  When I reverted back to the original the content loaded fine.  I was able to get my engine (XAGE) up and running and made a quick video - http://www.youtube.com/watch?v=oqIRZqCR2z8

Here's a summary of my experiences, not sure if this is of any use at all:

All ArrayLists had to be converted to List<> as this is not supported in Silverlight (a change I probably should have made anyway)
Some of the audio had to be removed as various things weren't supported (from memory: SoundEffectInstance, Media.Pause, Resume)
General performance is a little sketchy, but this probably says a lot more about my code than yours :)

A few questions if I may:

Will SilverSprite ever support Rendertargets?
Does SilverSprite do anything to the .xnb content?  
Does the Texture2D.FromFile function work? (for loading .bmp/.png) 
Does the user have to have the XNA 3.0 runtimes installed to use SilverSprite?  (I'm afraid I don't have a free machine to test with).
Mar 29, 2009 at 4:14 PM
Very nice!

ArrayLists: Yeah I had similar issues with one of my games, I was using non-generic collections. I suppose it wouldn't be that hard to implement ArrayList, I actually almost did this once.

Sound effects: We have some open issues on sound effects, these are high priority so hopefully will be fixed soon.

Performance: One thing that can improve performance is to use Silverlight's text rendering instead of the botmap font rendering, not sure which you are using or if you can even use the Silverlight text rendering. I haven't done any performance tuning yet, was thinking that I'll compile a WPF version of SilverSprite and then run it through some profiling tools.

Render Targets: Pretty much impossible in Silverlight 2, or at least very difficult. Silverlight 3 should make this possible.

Not sure what you mean about the xnb content.

I could probably get FromFile working, but you wouldn't be able to draw these textures with different colors, only the Alpha value of the color would be used.

There is no dependency on any XNA runtimes for the game to work, this also means it should work fine on Mac, and the Moonlight guys have tested a SilverSprite game on Moonlight 1.9 and it ran fine.
Mar 29, 2009 at 6:13 PM
Regarding spritefonts, as the 360 only supports this I've stuck with that format for simplicity.  I also forgot to mention that the SpriteEffect enums don't seem to be supported - in youtube clip you can see the characters walking backwards as SpriteEffect.FlipHorizontally has no effect in the SpriteBatch.Draw() call.

Multi-Platform:   I really had no idea that XAGE could go on platforms beyond Windows and X360 until now.  Being able to target more platforms is a massive incentive.  To be honest I'm amazed that there's not been more interest in SilverSprite on the XNA forums. I'll be keeping a close eye on this project as Silverlight matures.  Really excellent work.
Mar 29, 2009 at 8:05 PM
Yeah I noticed the problem with SpriteEffects in your video, I'll fix this soon.

Bill
Apr 4, 2009 at 3:44 AM
I have a fix in for SpriteEffects, everything except FlipHorizontal on bitmap text. It's checked in to source control, and will be in the next release.
Dec 21, 2009 at 10:56 AM

hi

i have the same problem with xnb files and i checked the Content  and it have the true path but it does not work

i looking for namespace SilverXna.IO but i did not find it

please help

Dec 21, 2009 at 1:36 PM

thanks i solve it

the problem was that the xnb files properties Build Action was set to none and i make it Content

and it works with me

thanks