首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Phaser加载图像

如何使用Phaser加载图像
EN

Stack Overflow用户
提问于 2015-01-17 04:41:21
回答 1查看 2.4K关注 0票数 0

我正在尝试学习如何使用Phaser,遵循关于如何加载图像的在线说明;phaser提供的示例之一是load图像示例。

这是Phaser提供的代码。

代码语言:javascript
复制
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

代码语言:javascript
复制
<html>
<head>
  <meta charset="UTF-8">
  <title>Experiments</title>
  <script src="../phaser.js"></script>
  <script src="game.js"></script>
</head>
<body>

</body>
</html>

我试图在我的服务器上运行这段代码(使用节点),但是我看不到图像,有人能解释我做错了什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-17 05:30:10

尝试在<div id="phaser-example"></div>标记中添加<body></body>

代码语言:javascript
复制
<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>

联署材料:

代码语言:javascript
复制
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');

}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27996228

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档