Search code examples
c#wpfcanvaspaint

C# wpf how to repaint canvas components


I'm new with C# programming, I always used Java. I'm trying to make a very simple version of a jumper (such as Doodle Jump) on Visual Studio and I created a WPF project. I need to know the best and the most common way to repaint the object on a canvas (like the player and the platforms, that are all rectangles), so that the objects keep to be updated (for example when I move the player etc.). Thanks in advance.


Solution

  • I suggest you take a look at transformations. One of the wonderful things about WPF is that you usually don't have to worry about the animation clock or repainting the screen when things change. To move something around the screen, like a rectangle, all you have to do is attach a transformation to it, then update the properties of the transformation. WPF's background rendering thread will automatically take care of the screen update. That article should get you started. Also check out Storyboards to do more elaborate animations.