This project is read-only.

Resize Physics Canvas to Fill Screen

Feb 18, 2013 at 3:23 AM
I have been working with the physics helper in a C#/XAML app for a dice roller in a windows store app I'm working on. It's a great library and has been super easy to learn (Thanks Andy). I've encountered one issue this past weekend that I'm not too sure how to get past, and was hoping for some community support.

The game I'm working on has no fixed screen size or aspect ratio, and I'm having difficulty getting the the physics canvas to fill it's parent container. I know that the PhysicsCanvas class has a ScaleToObject method that allows you to hook into a parent container's resize event, but it seems that this is more of a "fit to" resize versus a "fill" resize.

In my game, it could be expected that the screen size might change during game play (.e.g. Drag from 19" monitor to 24" monitor), and I have to resize and reposition the PhysicSprites that act as walls on the PhysicsCanvas.

It seems that the main issue is that the constructor of the BoundaryHelperBox2d is called during construction of the PhysicsCanvas, and since at this time, Width is NaN and ActualWidth is 0, it defaults to 1366x768, and I just can't find a way to easily resize it after the fact.

Any rate, that is my issue, I would greatly appreciate any help.
Aug 2, 2013 at 8:24 PM
Did you ever find a solution?
Nov 17, 2013 at 8:39 AM
I'm also curious to whether you found a solution?
Jan 27, 2014 at 2:36 AM
Edited Jan 27, 2014 at 2:39 AM
Ok I know this is a bit of an old thread but I encountered it while working with Physics Helper XAML for the first time. To resize the PhysicsCanvas I removed it from the Canvas in the XAML and added Width and Height with an Auto value. Then I placed it back in the grid. So an example of the part changed in one of the demos in the ucMainGame.xaml would be:
 <Grid x:Name="LayoutRoot" Background="Black" >
        
            <ph:PhysicsCanvas Background="CornflowerBlue" x:Name="cnvGame" DebugMode="False" MousePickEnabled="true" Width="Auto" Height="Auto">

                <local:ucBlock Canvas.Left="488" Canvas.Top="354" />
                <local:ucRagDoll Canvas.Left="632" Canvas.Top="356" />

            </ph:PhysicsCanvas>
 </Grid>
Hope that makes sense and proves useful to someone.