This project has moved and is read-only. For the latest updates, please go here.

Slow animation problem. How define bounce limits?

Dec 15, 2011 at 12:01 PM
Edited Dec 15, 2011 at 12:02 PM

When I compile and run some times, the animation start correctly (only few times), but other times start ultra slow. (this happen all time)

Have idea why that happen?
Im working under visual sutdio 2010  c#, on  windows 8, can be related to win 8 or c#, i hoppe no!!

The second problem is, how can make objects no go out of screen?

Example i want objects bounce inside the canvas, or if use a grid as container.
If can show with some example, i really apreciate that, this is my example code now, how can define the limits where objects bounce.
By example, in this simple example i have all inside canvas, and i want objects remain bouncing inside canvas.

Can show to me some example please?

Thanks for your help!!


        xmlns:d="" xmlns:mc="" mc:Ignorable="d" x:Class="test.MainWindow"

        Title="MainWindow" Height="480" Width="923" Loaded="Window_Loaded">

	<Canvas Margin="0,0,-16,-39">

		<physics:PhysicalBox x:Name="PhysicalBox" Height="480" Width="923" d:LayoutOverrides="Width, Height, Margin">
				<physics:GameLoop />

			<Rectangle Canvas.Left="80" Canvas.Top="0" Width="100" Height="100" Fill="DarkRed">
					<physics:RectangleBody />
			<Rectangle Canvas.Left="448" Canvas.Top="22" Width="100" Height="100" Fill="DarkCyan">
					<physics:RectangleBody />
			<Rectangle Canvas.Left="668" Canvas.Top="260" Width="100" Height="100" Fill="DarkGray">
					<physics:RectangleBody />
			<Rectangle Canvas.Left="728" Canvas.Top="48" Width="100" Height="100" Fill="DarkKhaki">
					<physics:RectangleBody />
			<Ellipse Canvas.Left="255" Canvas.Top="48" Width="50" Height="50" Fill="DarkGreen">
					<physics:CircleBody />
			<Ellipse Canvas.Left="292" Canvas.Top="145" Width="50" Height="50" Fill="DarkGoldenrod">
					<physics:CircleBody />
			<Rectangle Canvas.Left="-100" Canvas.Top="768" Width="1240" Height="10" Fill="Black">
					<physics:RectangleBody IsStatic="True" />



Dec 15, 2011 at 12:08 PM
Edited Dec 15, 2011 at 12:08 PM

Like you can see nothing special just running the example.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FarseerPhysics;
using XamlPhysics.WPF;

namespace test
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
        public MainWindow()

        private void Window_Loaded(object sender, RoutedEventArgs e)


Dec 17, 2011 at 12:21 PM

liserdarts please can send some reply about this?
Best regards.

Dec 20, 2011 at 9:13 AM

I don't see anything wrong with your code. There are a lot of samples in the source. It looks like you took the code from here.

You might want to try moving PhysicalBox.Clock.Start(); into a button click instead of the loaded event. That might fix the speed problems.

If you want objects to bounce off the sides you have to add static rectangles just beyond the edges. A lot of the samples do this on the bottom edge. That's what the last rectangle in your code was intended for. If you add one to the top and sides, bodies will just bounce off them.

Dec 20, 2011 at 2:02 PM
Edited Dec 20, 2011 at 2:22 PM

I add a button and on button i run :


That no fix the problem all continue running slow.
If i move the mouse over the screen all start run faster.

I think exist some problem with your lib and windows 8 and or C#
Is very sad cant use your lib is exactly what i need

i really appreciate if  you can take a look on this.

Want I upload a video so you can see the problem?

Bets regards.

Dec 23, 2011 at 9:57 AM

That is strange. 

I tried out the wpf samples and they are running slow for me. Even old versions. They never ran slow like that before. And the Silverlight samples still run just fine.

I'm still using the same OS. There must have been an update from Microsoft recently that affects WPF. I'll have to take a look at it some more.

Dec 23, 2011 at 7:26 PM

Thank you!!
Is great know finally you can see the problem.
I really hope you can fix this ASAP, your lib is the only one I see can handle physics in really extreme easy and simple way.
Hoppe you can fix this problem.
please if you found something update this post I check all days  : )
Also, a important questions, accept donations?

Dec 31, 2011 at 6:44 PM

No any news about this problem?

Bets regards.

Jan 10, 2012 at 9:07 PM

Me again, no any news?

Jan 16, 2012 at 10:07 PM

I finally got a chance to look at this and I think I have a workaround. I want you to try it out before I actually commit it.

All I did was change line 76 o f PhysicalBox.vb to this.




You can change that in your own copy of the code, or you can download a copy of the dll with the change here.

Jan 18, 2012 at 6:09 AM

Finally is fixed!!
Really awesome!!

I make more test and send some comments in the next hours!


Jan 18, 2012 at 1:06 PM

Is working, 100% working !!

 Please if have some free time can take a look on this?