Skip to main content
Tweeted twitter.com/#!/StackGameDev/status/371242146395086848
Embedded images.
Source Link
Anko
  • 13.5k
  • 10
  • 56
  • 82

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:

ThicknessAnimation ta = new ThicknessAnimation();

The event handling movement:

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;
      }
      else
      {
            ta.To = new Thickness(newX, newY, 0, 0);
      }
      ta.Duration = new Duration(TimeSpan.FromSeconds(2));
      Hansel.BeginAnimation(Grid.MarginProperty, ta);
}

ScreenShotScreenshot with annotations: http://i1118.photobucket.com/albums/k608/sealclubberr/clickToMove_zps9d4a33cc.png

ScreenShotscreenshot 1

Screenshot with example movement: http://i1118.photobucket.com/albums/k608/sealclubberr/clickToMove_zps51f2359f.jpg

screenshot 2

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:

ThicknessAnimation ta = new ThicknessAnimation();

The event handling movement:

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;
      }
      else
      {
            ta.To = new Thickness(newX, newY, 0, 0);
      }
      ta.Duration = new Duration(TimeSpan.FromSeconds(2));
      Hansel.BeginAnimation(Grid.MarginProperty, ta);
}

ScreenShot with annotations: http://i1118.photobucket.com/albums/k608/sealclubberr/clickToMove_zps9d4a33cc.png

ScreenShot with example movement: http://i1118.photobucket.com/albums/k608/sealclubberr/clickToMove_zps51f2359f.jpg

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:

ThicknessAnimation ta = new ThicknessAnimation();

The event handling movement:

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;
      }
      else
      {
            ta.To = new Thickness(newX, newY, 0, 0);
      }
      ta.Duration = new Duration(TimeSpan.FromSeconds(2));
      Hansel.BeginAnimation(Grid.MarginProperty, ta);
}

Screenshot with annotations:

screenshot 1

Screenshot with example movement:

screenshot 2

Added Images.
Source Link
ZeroPhase
  • 261
  • 3
  • 13

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:

ThicknessAnimation ta = new ThicknessAnimation();

The event handling movement:

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;
      }
      else
      {
            ta.To = new Thickness(newX, newY, 0, 0);
      }
      ta.Duration = new Duration(TimeSpan.FromSeconds(2));
      Hansel.BeginAnimation(Grid.MarginProperty, ta);
}

ScreenShot with annotations: http://i1118.photobucket.com/albums/k608/sealclubberr/clickToMove_zps9d4a33cc.png

ScreenShot with example movement: http://i1118.photobucket.com/albums/k608/sealclubberr/clickToMove_zps51f2359f.jpg

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:

ThicknessAnimation ta = new ThicknessAnimation();

The event handling movement:

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;
      }
      else
      {
            ta.To = new Thickness(newX, newY, 0, 0);
      }
      ta.Duration = new Duration(TimeSpan.FromSeconds(2));
      Hansel.BeginAnimation(Grid.MarginProperty, ta);
}

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:

ThicknessAnimation ta = new ThicknessAnimation();

The event handling movement:

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;
      }
      else
      {
            ta.To = new Thickness(newX, newY, 0, 0);
      }
      ta.Duration = new Duration(TimeSpan.FromSeconds(2));
      Hansel.BeginAnimation(Grid.MarginProperty, ta);
}

ScreenShot with annotations: http://i1118.photobucket.com/albums/k608/sealclubberr/clickToMove_zps9d4a33cc.png

ScreenShot with example movement: http://i1118.photobucket.com/albums/k608/sealclubberr/clickToMove_zps51f2359f.jpg

Clarified I was open to scrapping my current object types.
Source Link
ZeroPhase
  • 261
  • 3
  • 13

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:

ThicknessAnimation ta = new ThicknessAnimation();

The event handling movement:

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;
      }
      else
      {
            ta.To = new Thickness(newX, newY, 0, 0);
      }
      ta.Duration = new Duration(TimeSpan.FromSeconds(2));
      Hansel.BeginAnimation(Grid.MarginProperty, ta);
}

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.

Here's my movement code:

ThicknessAnimation ta = new ThicknessAnimation();

The event handling movement:

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;
      }
      else
      {
            ta.To = new Thickness(newX, newY, 0, 0);
      }
      ta.Duration = new Duration(TimeSpan.FromSeconds(2));
      Hansel.BeginAnimation(Grid.MarginProperty, ta);
}

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:

ThicknessAnimation ta = new ThicknessAnimation();

The event handling movement:

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;
      }
      else
      {
            ta.To = new Thickness(newX, newY, 0, 0);
      }
      ta.Duration = new Duration(TimeSpan.FromSeconds(2));
      Hansel.BeginAnimation(Grid.MarginProperty, ta);
}
deleted 82 characters in body; edited tags; edited title
Source Link
House
  • 73.5k
  • 17
  • 188
  • 276
Loading
Added code.
Source Link
ZeroPhase
  • 261
  • 3
  • 13
Loading
Added Details
Source Link
ZeroPhase
  • 261
  • 3
  • 13
Loading
Source Link
ZeroPhase
  • 261
  • 3
  • 13
Loading