When I select an image from a variety of options already on the server, and then click on the canvas, the image will be drawn at the click location.
The problem I am facing is that the first click the height and width of the image are zero and nothing is drawn. In the second click, it works fine, and it continues to work fine until I select another image, and then the first click works again.
I assume that since this only happens when a new image source is selected, it has something to do with the fact that the image is not yet loaded when the width and height are set.
Here is the code:
where the source is an example line: "sample / ball.png", "sample / dog.png"
Javascript
this.image_object = new Image(); this.image_object.src = source; this.width = this.image_object.width; this.height = this.image_object.height;
CoffeeScript
@image_object = new Image() @image_object.src = source @width = @image_object.width @height = @image_object.height
Any suggestions are welcome. This code is called only when a separate button is pressed, so the image cannot be called when the page loads.
EDIT:
I also want to mention that when manually adjusting the width / height of the image, the βnew image (52.52)β still requires two clicks because the image is not loaded.
source share