Canvas Cache
An image cache for canvas and key-value store for ImageData objects. Useful for fast draws in browser games with the putImageData()
method.
Install
npm install --save canvas-cache
Use
; // create cache instanceconst cache = ; /* your game draw method*/
Methods
has()
cache.has({ key, width, height })
Returns boolean if image with matching key
, width
, and height
exists.
get()
cache.get({ key, width, height })
Returns matching ImageData
object or undefined
.
set()
cache.set({ image, key, width, height })
Sets new image and returns a new ImageData
object.
delete()
cache.delete({ key, width, height })
Deletes matching image and returns boolean.
clear()
cache.clear()
Clear cache of all images.
Example
; // create cache instanceconst cache = ; // add imagecache; // get image datalet imageData = cache; // draw image dataconst canvas = document;const ctx = canvas; ctx;