CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2010
    Posts
    3

    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:
    Code:
    ThicknessAnimation ta = new ThicknessAnimation();
    The event handling movement:

    Code:
    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);
    }

  2. #2
    Join Date
    Feb 2010
    Posts
    3

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured