This project is read-only.

Dynamically resize Silversprite

Feb 17, 2010 at 12:35 PM

I'm in the process of adding some html controls in order to make it simpler to change a Silversprite game's settings.  I'm able to change the visual quality via a dropdown, which is great, but I'm not able change the size of the Silversprite object correctly.

Example:  http://www.clarvalon.com/XAGE/games/Awakener/FB/  (note: 'click to activate' message not displayed due to ongoing alpha-issue)

The dropdown uses javascript to change the div widths and heights, and also calls a method within the game itself to set the resolution internally, yet for some reason the size displayed doesn't change.

I've tried naming each of the SL UserControl's elements and setting the widths and heights in the code-behind also (i.e. XnaUserControl, LayoutRoot, me, XnaCanvas, XnaCanvasGame), but that doesn't seem to make a difference:

 

<UserControl x:Class="XAGE_Facebook.MainPage"
    Name="XnaUserControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300" xmlns:game="clr-namespace:Clarvalon.XAGE.dll;assembly=XAGE_DLL_Silverlight">
    <Grid x:Name="LayoutRoot" Background="Pink">
        <MediaElement Name="me"/>
        <Canvas Name="XnaCanvas">
            <game:XNAGame Name="XnaCanvasGame" />
        </Canvas>
    </Grid>
</UserControl>

 

<UserControl x:Class="XAGE_Facebook.MainPage"
    Name="XnaUserControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300" xmlns:game="clr-namespace:Clarvalon.XAGE.dll;assembly=XAGE_DLL_Silverlight">
    <Grid x:Name="LayoutRoot" Background="Pink">
        <MediaElement Name="me"/>
        <Canvas Name="XnaCanvas">
            <game:XNAGame Name="XnaCanvasGame" />
        </Canvas>
    </Grid>
</UserControl>

Any help appreciated.

Feb 18, 2010 at 12:10 PM

I've discovered that the problem only occurs when scaling up as opposed to down i.e. if I start the game at double size then it will scale down and back up again just fine, whereas starting at normal size and scaling it up x2 is where the problem occurs (only the original size is displayed - the top left hand quarter of what should actually be visible).

There must be something in the initialisation that is set up which isn't being reset when the scaling is changed and the GraphicsDevice reset, but I'm jiggered if I can find it.

Feb 18, 2010 at 3:57 PM

The last post reads like gibberish, so I've updated the example to illustrate the issue:  http://www.clarvalon.com/XAGE/games/Awakener/FB/

Scaling:  The game starts at x2.  Switching to x1 is fine.  The problem occurs when switching to x3, as only the screen area for the initial size (x2) is displayed.

Apr 22, 2010 at 8:52 PM

See my issue - Screen Resize Bug. It has a work around for this.

Apr 24, 2010 at 2:03 AM

Ok thanks I've checked in the recommended fix, please try it out.

Apr 24, 2010 at 8:00 AM

Thanks for the help guys, though I'm not able to test as I'm having a bit of bother with the latest build (47412).  

During initialisation I get a ContentLoadException ("TypeReader not registered").  It occurs when loading the first spritefont - the rectangle ContentTypeReader throws the exception in GetTypeReader (ContentTypeReaderManager.cs).

Apr 24, 2010 at 8:24 AM

After further investigation, it looks like it might be caused by the static method ReadTypeManifest (ContentTypeReaderManager.cs) never being called?  There is only one reference to it within the whole solution, and this is the only route to the AddTypeReader method.  Not sure how/where to call this though.

Apr 24, 2010 at 12:49 PM

Yes sorry it looks like I have a problem with my changes to the content readers, will let you know when it's resolved.

Apr 24, 2010 at 2:46 PM

Ok I've checked in a fix for the content reader problem, let me know if you still have issues.

Apr 24, 2010 at 3:28 PM

Fantastic, both the content reader and dynamic resize issues are fixed.  Being able to scale up and go fullscreen really adds a lot to the experience.  Many thanks to Bill & phenotype.