Moving image that was created by drawImage in canvas

谁都会走 提交于 2020-01-05 19:11:18

问题


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


回答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.



来源:https://stackoverflow.com/questions/12829429/moving-image-that-was-created-by-drawimage-in-canvas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!