我是JQuery和gameQuery的新手,所以我可能有很多错误,请耐心等待。
我只是按照教程来尝试学习如何制作网页游戏,但由于教程稍微过时,我需要改变一些事情。问题是我无法获得我的游戏"上班。 这是我的代码:
var PLAYGROUND_HEIGHT = 250;
var PLAYGROUND_WIDTH = 700;
var FPS = 30;
var bg1speed = 0.5
var bg2speed = 2
var bg3speed = 8
$("#playground").playground({height: PLAYGROUND_HEIGHT, width: PLAYGROUND_WIDTH});
$("#playground").addGroup("background", {width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT});
$("#playground").addGroup("actors", {width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT});
$("#playground").addGroup("playerMissileLayer",{width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT});
$("#playground").addGroup("enemiesMissileLayer",{width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT});
var background2 = new $.gQ.Animation({imageURL: "data/background2.png"});
var background3 = new $.gQ.Animation({imageURL: "data/background3.png"});
var background4 = new $.gQ.Animation({imageURL: "data/background4.png"});
var background5 = new $.gQ.Animation({imageURL: "data/background5.png"});
var background1 = new $.gQ.Animation({imageURL: "data/background1.png"});
var background6 = new $.gQ.Animation({imageURL: "data/background6.png"});
$("#background").addSprite("background1", {animation: background1, width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT});
$("#background").addSprite("background2", {animation: background2, width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT, posx: PLAYGROUND_WIDTH});
$("#background").addSprite("background3", {animation: background3, width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT});
$("#background").addSprite("background4", {animation: background4, width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT, posx: PLAYGROUND_WIDTH});
$("#background").addSprite("background5", {animation: background5, width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT});
$("#background").addSprite("background6", {animation: background6, width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT, posx: PLAYGROUND_WIDTH});
$("#playground").registerCallback(function(){
if($("#background1").x() <= -PLAYGROUND_WIDTH){
$("#background1").x(PLAYGROUND_WIDTH, False);
};
if($("#background2").x() <= -PLAYGROUND_WIDTH){
$("#background2").x(PLAYGROUND_WIDTH, False);
};
if($("#background3").x() <= -PLAYGROUND_WIDTH){
$("#background3").x(PLAYGROUND_WIDTH, False);
};
if($("#background4").x() <= -PLAYGROUND_WIDTH){
$("#background4").x(PLAYGROUND_WIDTH, False);
};
if($("#background5").x() <= -PLAYGROUND_WIDTH){
$("#background5").x(PLAYGROUND_WIDTH, False);
};
if($("#background6").x() <= -PLAYGROUND_WIDTH){
$("#background6").x(PLAYGROUND_WIDTH, False);
};
$("#background1").x(-bg1speed, true);
$("#background2").x(-bg1speed, true);
$("#background3").x(-bg2speed, true);
$("#background4").x(-bg2speed, true);
$("#background5").x(-bg3speed, true);
$("#background6").x(-bg3speed, true);
}, FPS);
$("#playground").startGame()
&#13;
<html>
<head>
<title>Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://gamequeryjs.com/jquery.gamequery.js"></script>
<script src = "data/Test.js"></script>
</head>
</html>
&#13;
实际上,此代码段会向我的错误显示不同的错误消息。那很奇怪。
无论如何,错误我得到的是:
Uncaught TypeError: Cannot read property 'children' of undefined
at Object.waitForResources (jquery.gamequery.js:313)
at jquery.gamequery.js:306
有谁知道为什么会这样?
旁注:我认为gameQuery应该抛出更多自定义异常,这会让像我这样的人更轻松地解决我们做错的事情。