How do I implement movement in a WPF Adventure game?
I'm working on making a short WPF adventure game. The only major hurdle I have right now is how to animate objects on the screen correctly. I've experimented with DoubleAnimation and ThicknessAnimation both enable movement of the character, but the speed is a bit erratic. The objects I'm trying to move around are labels in a grid, I'm checking the mouse's position in terms of the canvas I have the grid in.
Does anyone have any suggestions for coding the movement, while still allowing mouse clicks to pick up items when needed? It would be nice if I could continue using the Visual Studio GUI Editor. By the way, I'm fine with scrapping labels in a grid for a more ideal object to manipulate.
Here's my movement code:
The event handling movement:
ThicknessAnimation ta = new ThicknessAnimation();
private void Hansel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
ta.FillBehavior = FillBehavior.HoldEnd;
ta.From = Hansel.Margin;
double newX = Mouse.GetPosition(PlayArea).X;
double newY = Mouse.GetPosition(PlayArea).Y;
if (newX < Convert.ToDouble(Hansel.Margin.Left))
//newX = -1 * newX;
ta.To = new Thickness(0, newY, newX, 0);
else if (newY < Convert.ToDouble(Hansel.Margin.Top))
newY = -1 * newY;
ta.To = new Thickness(newX, newY, 0, 0);
ta.Duration = new Duration(TimeSpan.FromSeconds(2));
Re: How do I implement movement in a WPF Adventure game?
Sorry, if I missed the edit post option.
Here are some images with annotations for what I am trying to do.
Any help with getting this to work or why my current code doesn't function as intended would be greatly appreciated.