Javascript 游戏,未定义模块 raphael [英] Javascript game, module raphael not defined

查看:60
本文介绍了Javascript 游戏,未定义模块 raphael的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里开发游戏引擎:http://synodins.com/apps/tank_fight但是现在,由于某种原因,它不再运行了.我无法启动 Raphael 模块,当我使用 mozilla Web 调试器运行站点时,我收到未定义 Raphael".但这没有任何意义,因为它在 raphael.js 模块中有非常明确的定义.

I am developing a game engine here: http://synodins.com/apps/tank_fight But now, for some reason, it doesn't run anymore. I cannot initiate the Raphael module, when i run the site with mozilla web debugger, i get "Raphael is not defined". But that doesn't make any sense because it's very clearly defined in the raphael.js module.

此外,有时游戏运行良好,例如,我每 20 次尝试一次.并且没有明确的模式使其工作.
我在尝试启动 raphael 之前打印出 Hello world 1,在尝试之后打印出 hello world 2.
有人能看出问题是什么吗?

Also, occationally the game runs fine, like, every 20th time i try. And there's no clear pattern to what makes it work.
I print out Hello world 1 before trying to initiate raphael, and hello world 2 after trying.
Can anybody see what the problem is?

推荐答案

load_script 调用块异步加载脚本.这就是为什么似乎没有明确的模式.

The block of load_script calls loads the scripts asynchronously. This is why there appears to be no clear pattern.

无法保证在以下行之前加载 raphael.js(因此定义了 Raphael):

There is no guarantee that raphael.js is loaded (and therefore, that Raphael is defined) by the time that the line:

var playing_area = Raphael(0,50,1600,1600);

被调用.

在尝试使用在外部脚本中定义的变量之前,您应该等到整个文档准备就绪.一般情况下,这是文档的onload事件.像 jquery 这样的各种库也提供了他们自己的就绪"事件,如果你使用它们,你可以绑定.

You should wait until the whole document is ready before attempting to use variables defined in external scripts. Under normal circumstances, this is the onload event of the document. Various libraries like jquery also offer their own "ready" event, that you could tie to if you use them.

您是否有任何理由按照自己的方式加载脚本,而不是简单地使用标记,如下所示?

Is there any reason why you load the scripts in the way you do, rather than simply using markup, as below?

<script src="raphael.js"></script>

这篇关于Javascript 游戏,未定义模块 raphael的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆