Make a bitmap wrap around the canvas for infinite scrolling

前端 未结 3 738
北恋
北恋 2020-12-12 02:56

I am looking for a way to wrap a bitmap image around the canvas, for an infinite scrolling effect. I\'m looking at EaselJS but clean javascript code will also suffice.

3条回答
  •  星月不相逢
    2020-12-12 03:09

    Start with a good landscape image.

    enter image description here

    Flip the image horizontally using context.scale(-1,1).

    enter image description here

    Combine the flipped image to the right side of the original image.

    enter image description here

    Because we have exactly mirrored the images, the far left and right sides of the combined image are exactly the same.

    Therefore, as we pan across the combined image and “run out of image”, we can just add another copy of the combined image to the right side and we have infinite + seamless panning.

    Here's code and a Fiddle: http://jsfiddle.net/m1erickson/ywDp5/

    
    
    
     
    
    
    
    
    
    
    
    
    
        

提交回复
热议问题