Skip to content Skip to sidebar Skip to footer

Moving Image That Was Created By Drawimage In Canvas

How just move image in canvas? There are no x\y coordinates which I can change by += or -=.

Solution 1:

Canvas is an immedate drawing surface. When you make a call like drawImage the canvas renders the bitmap to the context and then forgets that anything ever happened. It keeps track of nothing.

That means you need to keep track of everything. If you want the image you move, you need to clear the canvas and redraw the image (and everything else in the scene) at a different location than before.

This comes up a lot in various ways so I made a tutorial on managing the state of drawn objects and canvas interactivity that serves as a decent introduction to this topic. The tutorial uses rectangles that you can drag around the screen, but using images is nearly identical.

Post a Comment for "Moving Image That Was Created By Drawimage In Canvas"