hollowdoor Posted March 26, 2015 Share Posted March 26, 2015 So I have an image in a javascript Image object. What would be the best way to add that image to a game? Link to comment Share on other sites More sharing options...
JazzAceman Posted March 27, 2015 Share Posted March 27, 2015 You can use the canvas' toDataURL-method to generate data URL for your image, and than use the Phaser.Cache's addImage() method to apply it to your game:var image = document.getElementById("fez");var canvas = document.createElement('canvas');canvas.width = image.width;canvas.height = image.height;var context = canvas.getContext('2d');context.drawImage(image, 0, 0);var dataURI = canvas.toDataURL("image/png");var data = new Image();data.src = dataURI;game.cache.addImage('myImage', dataURI, data); jdnichollsc 1 Link to comment Share on other sites More sharing options...
Recommended Posts