我有以下用于 Phaser 游戏的代码。它只是用于通过使用 AJAX 从 JSON 文件加载信息来获得关卡的视觉概念。
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>hello phaser!</title>
<script src="phaser.min.js"></script>
<script src="jquery.min.js"></script>
</head>
<body>
<div id="results"></div>
<script type="text/javascript">
var game = new Phaser.Game(1024, 768, Phaser.AUTO, '', { preload: preload, create: create,renderer:renderer});
var background;
function preload ()
{
game.load.image('bg','bg.png');
game.load.image('mothership', 'bird.png');
game.load.image('turret','turret.png');
}
function create ()
{
//game.add.sprite(31,725,"mothership");
//game.add.sprite(100,100,"turret");
//background=game.add.sprite(0,0,"bg");
//background.scale.setTo(5,7);
}
function renderer()
{
}
$.ajax({
url: "TestFile5.json",
dataType: 'json',
contentType:"application/json",
success: function(response) {
//here you can use the response
//response can be passed to what ever js file you need.
game.add.sprite(response.mothership.posx, response.mothership.posy, "mothership");
game.add.sprite(response.Turret0.posx, response.Turret0.posy, "turret");
game.add.sprite(response.Turret1.posx, response.Turret1.posy, "turret");
game.add.sprite(response.Turret2.posx, response.Turret2.posy, "turret");
},
error: function(response1){
alert('response error')
}
});
</script>
</Body>
</html>
我已经将它与 JSON 文件和图像一起加载到我的在线服务器上,但它似乎没有使用game.add.sprite()
AJAX 回调中的函数加载图像。我得到带有占位符图像的屏幕。位置正确,但未加载图像。这可能是什么原因造成的,我该如何解决?