I am trying to implement infinite scrolling as in flappy bird game. I decreased x position and drew the background and again drew the clipped image part. But it is not seamless as in other game. I could see the part where the image is joined.Is there any elegant way to do it? Here is the code
window.onload = function()
{
    var xpos=0;
    var ypos=0;
    var canvas = document.getElementById("screen");
    var ctx = canvas.getContext("2d");
    var bg = new Image();
    bg.src="background2.png";
    bg.onload = function(){
        update();
    };
function update()
{   xpos-=5;
    if(xpos==-750)
    {
        xpos = 0;
    }
    ctx.drawImage(bg,xpos,ypos,canvas.width,canvas.height);
    ctx.drawImage(bg,bg.width+xpos,ypos,canvas.width,canvas.height);
    setTimeout(update,30);
}
};