我正在尝试学习如何使用Phaser,遵循关于如何加载图像的在线说明;phaser提供的示例之一是load图像示例。
这是Phaser提供的代码。
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create });
function preload() {
// You can fill the preloader with as many assets as your game requires
// Here we are loading an image. The first parameter is the unique
// string by which we'll identify the image later in our code.
// The second parameter is the URL of the image (relative)
game.load.image('einstein', 'assets/pics/ra_einstein.png');
}
function create() {
// This creates a simple sprite that is using our loaded image and
// displays it on-screen
game.add.sprite(0, 0, 'einstein');
}html
<html>
<head>
<meta charset="UTF-8">
<title>Experiments</title>
<script src="../phaser.js"></script>
<script src="game.js"></script>
</head>
<body>
</body>
</html>我试图在我的服务器上运行这段代码(使用节点),但是我看不到图像,有人能解释我做错了什么吗?
发布于 2015-01-17 05:30:10
尝试在<div id="phaser-example"></div>标记中添加<body></body>
<html>
<head>
<meta charset="UTF-8">
<title>Experiments</title>
<script src="../phaser.js"></script>
<script src="game.js"></script>
</head>
<body>
<div id="phaser-example"></div>
</body>
</html>联署材料:
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create });
function preload() {
// You can fill the preloader with as many assets as your game requires
// Here we are loading an image. The first parameter is the unique
// string by which we'll identify the image later in our code.
// The second parameter is the URL of the image (relative)
game.load.image('einstein', 'assets/pics/ra_einstein.png');
}
function create() {
// This creates a simple sprite that is using our loaded image and
// displays it on-screen
game.add.sprite(0, 0, 'einstein');
}https://stackoverflow.com/questions/27996228
复制相似问题