Horrible Canvas GetImageData() / PutImageData() performance on mobile

前端 未结 2 1418
梦如初夏
梦如初夏 2021-02-15 15:24

I\'m doing a little HTML5 game and, while loading my sprites at the beginning of the map, I do some processing with GetImageData() / looping over all the image / PutImageData().

2条回答
  •  时光取名叫无心
    2021-02-15 15:54

    Phrogz has the right idea. You really just want to paint a half-transparent (or ratio-transparent) black over the whole thing with 'source-atop' globalCompositeOperation.

    Like this: http://jsfiddle.net/F4cNg/

    There was actually a good question on sophisticated darkening like this but the author deleted it which is a real shame. It's certainly possible to make dark-masks on drawn stuff, even with sophisticated shapes. They may not help you, but for the sake of completeness and for anyone searching for "darken canvas" stuff where some parts are kept light (exclusion zones), that can be done with the 'xor' globalCompositeOperation, like this:

    http://jsfiddle.net/k6Xwy/1/

提交回复
热议问题