Search code examples
htmlcanvastranslate

html5 canvas translate 2D side scrolling camera


Can anyone help or give ideas on how to use HTML5 canvas translate to make a scrolling camera to follow an object?


Solution

  • You want to use ctx.translate(x, y) to move the canvas context while you draw your objects normally.

    For more detail and suggestions see my answer here: 2D side scrolling camera view in html5

    The accepted answer for that question is another valid way of doing things but is much worse performance-wise.