PhysicsCameraBehavior on WP7

Apr 3, 2010 at 8:02 AM

I'm trying to create a scrolling game for the Windows Phone 7.  I've created a test app but the PhysicsCameraBehavior does not do what I'd expect.  Here's a XAML snippet from my main page:

 

     <Ellipse x:Name="ball" Height="52" Canvas.Left="305" StrokeStartLineCap="Flat" StrokeEndLineCap="Flat" StrokeThickness="4" StrokeMiterLimit="10" StrokeLineJoin="Miter" Width="48" RenderTransformOrigin="0.674,0.34" Stroke="{StaticResource PhoneBackgroundBrush}" Fill="#FFFD1B04" Canvas.Top="160">
            <i:Interaction.Behaviors>
                <pb:PhysicsObjectBehavior IsStatic="False" Mass="2" BoundaryElement="ball" />
                <pb:PhysicsCameraBehavior/>
            </i:Interaction.Behaviors>
        </Ellipse>

 

I've looked at the PhysicsCameraBehavior and it does not expose any properties, does this mean I should access these features in C# with CameraControllerMain?

Coordinator
Apr 3, 2010 at 1:15 PM

The Camera Behavior will just "scroll" the main Physics Canvas when the target object moves, so that the object stays centered.

Your XAML worked OK for me when I placed it inside a Physics Controller (and gave the ball something to land on). By the way, you CAN get a reference to CameraControllerMain for more advanced camera effects if you need them.

    <Canvas x:Name="LayoutRoot" Background="{StaticResource PhoneBackgroundBrush}">
       <i:Interaction.Behaviors>
              <pb:PhysicsControllerBehavior/>
       </i:Interaction.Behaviors>
       <Rectangle Fill="#FFF4F4F5" Height="60" Canvas.Left="8" Stroke="Black" Canvas.Top="732" Width="464">
              <i:Interaction.Behaviors>
                     <pb:PhysicsObjectBehavior IsStatic="True"/>
              </i:Interaction.Behaviors>
       </Rectangle>

        <Ellipse x:Name="ball" Height="52" Canvas.Left="305" StrokeStartLineCap="Flat" StrokeEndLineCap="Flat" StrokeThickness="4" StrokeMiterLimit="10" StrokeLineJoin="Miter" Width="48" RenderTransformOrigin="0.674,0.34" Stroke="{StaticResource PhoneBackgroundBrush}" Fill="#FFFD1B04" Canvas.Top="160">
            <i:Interaction.Behaviors>
                <pb:PhysicsObjectBehavior IsStatic="False" Mass="2" BoundaryElement="ball" />
                <pb:PhysicsCameraBehavior/>
            </i:Interaction.Behaviors>
        </Ellipse>

    </Canvas>



 

Apr 3, 2010 at 2:49 PM

Thanks for your quick response.