Saturday, 31 August 2013

Create a New Image() in 1 Line

Create a New Image() in 1 Line

Right now, I'm using
var lifeIcon = new Image();
lifeIcon.src = "img/System/lifeIcon.png";
Is there a way to do the same thing in 1 line?
I tried
var lifeIcon = (new Image()).src = "img/System/lifeIcon.png";
But it doesn't work. lifeIcon is considered as a string...
Thanks.
Note: My goal is to use the Image in a canvas. Ex:
ctx.drawImage(lifeIcon,0,0)

No comments:

Post a Comment