This project is read-only.

Is there a camera?

Oct 24, 2012 at 11:30 PM

I looked in the physics canvas but couldn't find it.

Oct 26, 2012 at 1:05 PM
Edited Oct 26, 2012 at 1:09 PM

You're right, the Camera that was present in the original Physics Helper for Blend/Silverlight has not yet been ported.

You can simulate a camera by changing the PhysicsCanvas TransformRoot properties. It goes something like this: set the TranslateX and TranslateY properties to the _negative_ x,y of the object you are trying to track. Do this in the TimerLoop event (see the advanced sample for an example of timerloop being used).

cnvGame.TransformRoot.TranslateX = - targetX;
cnvGame.TransformRoot.TranslateY = - targetY;

Oct 26, 2012 at 3:36 PM

cool I got it working.

Oct 26, 2012 at 3:40 PM

One other thing about scrolling - you will want to test your app on a somewhat low-powered device to make sure performance is OK. Also if you have a long scrolling area, you will need to introduce some virtualization - that is, logic that disables items that are out of view.

Hope this helps!

Nov 3, 2012 at 2:59 AM

why  i can not run   two line code ,above?

when i run it ,it   will throw NullReferenceException  exception.i find no object assigned to cnvGame.TransformRoot,so i manually assign it.

I using the following code

        <Canvas x:Name="cnvGameOuter">
            <ph:PhysicsCanvas x:Name="cnvGame" Background="CornflowerBlue" DebugMode="False"  Width="1600" Height="480" MousePickEnabled="True" Tap="cnvGame_Tap">



        private void cnvGame_Tap(object sender, GestureEventArgs e)
                cnvGame.TransformRoot = new CompositeTransform();
                cnvGame.TransformRoot.TranslateX = -100;//test translation,but nothing happend!
                cnvGame.TransformRoot.TranslateY = 0;
            catch (Exception ee)
 but no x  translation  i see in the run result! Why?


Nov 16, 2012 at 12:25 PM


i solved it by myself, cnvGame.TransformRoot can be accessed only in TimerLoop and Collision Event, i dont know why?

Jan 2, 2013 at 7:39 PM

I cant get it to work and I really need it with zooming as well.


<Grid x:Name="LayoutRoot" Style="{StaticResource LayoutRootGridStyle}">
        <Canvas x:Name="cnvGameOuter">
            <FarseerHelper:PhysicsCanvas x:Name="cnvGame" Background="CornflowerBlue" Height="480" Width="640" MousePickEnabled="True">
                <FarseerHelper:PhysicsSprite x:Name="Ground" Height="43" Width="1199" Canvas.Left="120" Canvas.Top="404" IsStatic="True">
                    <Rectangle Fill="#FF1818C9" HorizontalAlignment="Left" Height="43" Stroke="Red" VerticalAlignment="Top" Width="1199"  />                
                <!--<FarseerHelper:PhysicsSprite x:Name="Ball" Height="140" Canvas.Left="262" Canvas.Top="99" Width="40" ShapeType="Ellipse" >
                    <Ellipse Fill="Black" Height="140" Width="40" Stroke="Red"></Ellipse>
                <FarseerHelper:PhysicsSprite x:Name="CarBody" Height="130" Canvas.Left="200" Canvas.Top="100" Width="280" >
                    <Path Data="M-899,-447 L-902.5,-270.5 -536.5,-270.5 -644.5,-369.5 -680.5,-450.5" Fill="#FF9E9E9E" Height="130" Stretch="Fill" Stroke="Black" Width="280" RenderTransformOrigin="0.5,0.5">


void cnvGame_TimerLoop(object source)
            //// this event is fired for EACH Timer tick of the simulation.
            //if ((DateTime.Now - _dtLastFpsUpdate).TotalMilliseconds > 1000)
            //    tbStatus.Text = String.Format("{0} fps with {1} UIElements, {2} bodies, {3} joints, {4} collisions", cnvGame.LastFPS, cnvGame.Children.Count(), cnvGame.Simulator.BodyList.Count, cnvGame.Simulator.JointList.Count, _collisionCount);
            //    _dtLastFpsUpdate = DateTime.Now;
            //    _collisionCount = 0;

            //if (cnvGame.TransformRoot == null)
            cnvGame.TransformRoot = new CompositeTransform();
            cnvGame.TransformRoot.TranslateX = -100;//test translation,but nothing happend!
            cnvGame.TransformRoot.TranslateY = 0;
            //cnvGame.TransformRoot = new CompositeTransform();
            //cnvGame.TransformRoot.TranslateX = -CarBody.Position.X;
            //cnvGame.TransformRoot.TranslateY = -CarBody.Position.Y;
            //cnvGame.TransformRoot.Transform(new Point(-CarBody.Position.X, -CarBody.Position.Y));
As you can see I tried a bunch of things. Is it just me not knowing some basic stuff about transforming?
I also tried to debug the code and see if the TransformRootTranslateX got changed and it did, every time. still the camera isn't going anywhere :(.

Love the new changes Andy. I like the new way of having the normal ui-elements inside the speciel elements "physicalsprites". There sure is a huge difference between this version and the physical helper version that supported WPF. I got stuck there trying to zoom with the camera. Figured I better tried this new version even though I had to do it in Silverlight instead. Now I am stuck again :P.