HTML5 Canvas Performance: Loading Images vs Drawing

后端 未结 7 579
渐次进展
渐次进展 2021-02-04 08:23

I\'m planning on writing a game using javascript / canvas and I just had 1 question: What kind of performance considerations should I think about in regards to loading images vs

相关标签:
7条回答
  • 2021-02-04 08:50

    If you're drawing simple shapes with solid fills then drawing them procedurally is the best method for you.

    If you're drawing more detailed entities with strokes, gradient fills and other performance sensitive make-up you'd be better off using image sprites. Generating graphics procedurally is not always efficient.

    It is possible to get away with a mix of both. Draw graphical entities procedurally on the canvas once as your application starts up. After that you can reuse the same sprites by painting copies of them instead of generating the same drop-shadow, gradient and strokes repeatedly.

    If you do choose to draw sprites you should read some of the tips and optimization techniques on this thread.

    My personal suggestion is to just draw shapes. I've learned that if you're going to use images instead, then the more you use the slower things get, and the more likely you'll end up needing to do off-screen rendering.

    0 讨论(0)
提交回复
热议问题