0

So Im building a game and have a js script which loads a background image for each level only problem is I want the background to be in a certain position. How would I achieve this within the script?

My code is as follows:

var levels = {
    level1: {
                level: [[["0","1","0","1"],["0","0","0","0"],["0","0","0","0"],["0","0","0","0"],["0","0","0","0"],["0","0","0","0"]],[["0","0","1","1"],["0","1","1","0"],["0","0","0","0"],["0","0","0","0"],["0","0","0","0"],["0","0","0","0"]],[["0","0","0","0"],["0","0","1","1"],["1","1","0","0"],["0","0","0","0"],["0","0","0","0"],["0","0","0","0"]],[["0","0","0","0"],["0","0","0","0"],["0","0","1","1"],["1","0","1","0"],["1","0","1","0"],["1","1","0","0"]]],
                backgroundURL : "http://google.co.uk/level1.jpg" 
            },
June
  • 39
  • 7

1 Answers1

1

Just use the css attibute background-position, as described in another stackoverflow post.

Provided you use jQuery, you could do

$('#canvas').css('background-position', '10px 10px');

where

<div id="canvas">

is the relevant HTML element.

Community
  • 1
  • 1