Oct 10, 2010 at 2:01 AM
Edited Oct 10, 2010 at 2:02 AM
I've got a moving rectangle!! (but gravity does not seem to work)
Using the dispatch timer instead of the storyboard they use in the silverlight examples. the storyboard didn't work for some reason.
I am having trouble with gravity. my rectangle moves down now, but does not seem to accelerate.
The world has been created with gravity though.
Im not sure if i need a gravityController, though i have tried that.
heres my code so far.
/// Interaction logic for MainWindow.xaml
public partial class MainWindow : Window
World _world = new World(new Vector2(0, -20));
DispatcherTimer dispatcherTimer = new DispatcherTimer();
// Set up the timer for game updates
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 0,0,100);
// create a body and place it in position defined by Vector2
_rectBody = BodyFactory.CreateBody(_world,new Vector2(5, 50));
_rectBody.Mass = 100;
_rectBody.LinearDamping = 0;
_rectBody.BodyType = BodyType.Dynamic;
label1.Content = _world.Gravity.Y;
_rectBody.IgnoreGravity = false;
void dispatcherTimer_Tick(object sender, EventArgs e)
label2.Content = this._rectBody.Position.Y;
translateTransform.Y = 50 -_rectBody.Position.Y;
My goal firstly is still to get a simple example working with WPF (before starting my proper project). when i get this done, i will post the code, so hopefully its easier for the next person who tries this.
Any help with gravity would be much appreciated.