var pipe_pair = function(x) { var gap = 100; var y = Math.random_range(0,200) - gap; world.spawn(ur.pipe).pos = [x,y]; var pipe2 = world.spawn(ur.pipe); pipe2.scale = [1,-1]; pipe2.pos = [x,y+gap]; var wall = world.spawn(ur.scorewall); wall.pos = [x+30,y+gap/2]; wall.edge2d.sensor = true; } var gndx = -1000; var lastpipe = Game.camera.right() - 100; this.start = function() { pipe_pair(lastpipe); } this.update = function() { while (gndx < Game.camera.right()) { var g = world.spawn(ur.ground); g.pos = [gndx,-200]; gndx += g.width()-3; } if (Game.camera.pos.x > lastpipe-200) { lastpipe += 200; pipe_pair(lastpipe); } }