Posts

Showing posts with the label loading

Images not displaying the first time in this object program in JS

Images not displaying the first time in this object program in JS I am making a battleship game with polar coordinates. After the user chooses two points, a battleship should be drawn in the middle. My Battleship constructor looks like this: function Battleship(size, location, source){ this.size = size; //initializing the image this.image = new Image(); this.image.src = source; this.getMiddlePoint = function(){ //get midpoint of ship ... } this.distanceBetween = function(t1, t2){ //dist between two points } this.display = function(){ var point = [this.radius]; point.push(this.getMiddlePoint()); point = polarToReal(point[0], point[1] * Math.PI / 12); //now point has canvas coordinates of midpoint var width = this.distanceBetween(this.info[0][0], this.info[this.info.length-1][0]); var ratio = this.image.width / width; ...