How to keep objects within a container

Mar 20, 2010 at 8:09 PM


I've been trying to setup two rectangles to float inside a box (in order to prevent them to go out of screen.
In order to achieve this, I'm using a zero gravity PhysicsControllerBehavior and PhysicsMagnetBehavior to keep rectangle apart.
When putting another rectangle on the bottom of the screen and making it static, it gives a bouncing. However, having the container all around the screen prevent the PhysicsMagnetBehavior from working.
Is it impossible to represent the container as one object? Am I forced to have 4 objects all around the scene? Is there any other way to 'contain' objects on screen?

Thanks in advance for your help,


The XAML is the following:

    d:DesignWidth="1024" d:DesignHeight="768">
    <Canvas x:Name="LayoutRoot" Background="White">
            <pb:PhysicsControllerBehavior MousePickEnabled="True" GravityVertical="0"/>
        <Rectangle x:Name="NT1" Width="200" Height="100" Fill="Beige" Stroke="Black" Canvas.Top="10" Canvas.Left="0">
                <pb:PhysicsObjectBehavior x:Name="test1" Mass="9" CollisionGroup="5"/>
                <pb:PhysicsMagnetBehavior Magnetism="-25" MaxDistance="200"/>
        <Rectangle x:Name="NT2"  Width="200" Height="100" Fill="Beige" Stroke="Black" Canvas.Top="10" Canvas.Left="200">
                <pb:PhysicsObjectBehavior CollisionGroup="5" Mass="9"/>
                <pb:PhysicsMagnetBehavior Magnetism="-25" MaxDistance="200"/>
        <Rectangle x:Name="Container" Stroke="Black" Canvas.Top="0" Canvas.Left="0" Width="1024" Height="768">
                <pb:PhysicsObjectBehavior IsStatic="True"/>


Mar 22, 2010 at 12:20 PM

Yes, you do need the four separate objects (rectangles, etc) around the outside to contain the other objects. However you can place these outside the viewable area of the game so that it just appears as though everything is contained on the screen.

Mar 22, 2010 at 3:42 PM

Thank you for the quick answer. I'll got for the 'out of  sight' option.

Thank you too for this library!