所以我正在建立一个游戏,并且有一个js脚本,只为每个级别加载背景图像问题,我希望背景处于某个位置。如何在脚本中实现这一目标?
我的代码如下:
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"
},
答案 0 :(得分:0)
只需使用css属性background-position,如another stackoverflow post。
中所述如果你使用jQuery,你可以做
$('#canvas').css('background-position', '10px 10px');
,其中
<div id="canvas">
是相关的HTML元素。