所以我今天决定和LimeJS玩一玩,我以前从来没有用过闭包,所以这对我来说也是新的。我一开始就遇到了一个小问题,我不知道出了什么问题。
到目前为止,我的项目只有三个文件:firstGame.html、firstGame.js、`player.js
firstGame.html:
<!DOCTYPE HTML>
<html>
<head>
<title>firstGame</title>
<script type="text/javascript" src="../closure/closure/goog/base.js"></script>
<script type="text/javascript" src="firstGame.js"></script>
<script type="text/javascript" src="player.js"></script>
</head>
<body onload="firstGame.start()"></body>
</html>firstGame.js:
goog.provide('firstGame');
//get requirements
goog.require('lime.Director');
goog.require('lime.Scene');
goog.require('lime.Layer');
goog.require('lime.Circle');
goog.require('lime.Label');
goog.require("lime.Sprite");
goog.require('lime.animation.Spawn');
goog.require('lime.animation.FadeTo');
goog.require('lime.animation.ScaleTo');
goog.require('lime.animation.MoveTo');
goog.require("firstGame.Player");
// entrypoint
firstGame.start = function(){
var director = new lime.Director(document.body,1024,768);
director.makeMobileWebAppCapable();
scene = new lime.Scene();
var background = new lime.Sprite().setSize(1524,768).setPosition(0,0).setFill(0,0,0).setAnchorPoint(0,0);
var player = new firstGame.Player();
scene.appendChild(background);
// set current scene active
director.replaceScene(scene);
}
//this is required for outside access after code is compiled in ADVANCED_COMPILATIONS mode
goog.exportSymbol('firstGame.start', firstGame.start);最后,player.js(这个想法是一个定制的ui组件,所以我从Sprite继承):
goog.provide("firstGame.Player');
goog.require('lime.Sprite');
// new constructor
firstGame.Player = function(){
// call parents constructor
goog.base(this);
// custom initialization code
this.color_ = 'red';
}
// define parent class
goog.inherits(firstGame.Player,lime.Sprite);然后我运行了lime.py update (不确定是否需要,因为我只是在添加一个类,而不是一个全新的命名空间,但我认为我应该是安全的)
当我加载页面时,我得到了上面提到的意外令牌错误,这发生在player.js的第1行goog.provide()上。现在,如果我从html文件中的脚本路径中删除player.js,我发现我的其他代码运行良好,这表明我正在按预期的方式链接到闭包库。当我尝试在player.js中使用它时,我就遇到了这个问题。我的第一个倾向是,在解析闭包库之前,可能代码正在执行,在加载闭包时,我找了一些挂钩,但是找不到任何东西。我在谷歌上搜索了一下,却没有找到答案。我觉得我错过了一些简单的东西,但无法完全理解。如果有人有任何建议,我会很感激的,非常感谢!
发布于 2014-04-06 19:08:15
goog.provide("firstGame.Player');应该是
goog.provide('firstGame.Player');你的qoutes不匹配。
https://stackoverflow.com/questions/22898573
复制相似问题