Learn Create Your Own Split Screen

Next Page

All we need do is:
var gravity = 0.25; MySprite.prototype.Do_Frame_Things = function() { if (this.visible) ctx.drawImage(this.MyImg, this.x, this.y); // draw the thing this.x = this.x + this.velocity_x; this.y = this.y + this.velocity_y; // move the thing this.velocity_y = this.velocity_y + gravity; // accelerate by gravity if (this.x < 0) {this.velocity_x= -this.velocity_x}; if (this.x + this.MyImg.width > myCanvas.width) {this.velocity_x= -this.velocity_x}; if (this.y + this.MyImg.height > myCanvas.height) {this.velocity_y= -this.velocity_y}; }
Such a simple change, but such an impressive effect.