Destroying a Sprite or Image

To destroy a sprite or image that has been added to the DGM, simply call the destroy function and pass it the sprite/image variable.

//define the gameCanvas using the HTML canvas element
var gameCanvas = dgm.setupCanvas(document.getElementById("gameCanvas"));
 
//setup a wooden block object to be destroyed
var woodenBlock_data = {
  "id": "wooden_block",
  "x": 0,
  "y": 0,
  "src": 'images/wooden-block.png'
};
 
//add the wooden block object to the canvas
var woodenBlock = dgm.configImg(woodenBlock_data, gameCanvas);
 
//after 5 seconds, destroy the block
setTimeout(function() {
  dgm.destroy(woodenBlock);
}, 5000);