所以,我正在自学Canvas(HTML5)并且编写了大部分简单的游戏引擎.它是空间场景(行星,恒星,天体等)的二维表示.我的默认"Sprite"类有一个像这样的帧监听器:
"baseClass"包含一个允许继承的函数,并将"a"应用于"this.a".所以,"var aTest = new Sprite({foo:'bar'});" 会使"aTest.foo ='bar'".这就是我将对象暴露给对方的方式.
Sprite = baseClass.extend({
init: function(a){
baseClass.init(this, a);
this.fields = new Array(); // list of fields of gravity one is in. Not sure if this is a good idea.
this.addFL(function(tick){ // this will change to be independent of framerate soon.
// gobjs is an array of all the Sprite objects in the "world".
for(i = 0; i < gobjs.length; i++){
// Make sure its got setup correctly, make sure it -wants- gravity, and …Run Code Online (Sandbox Code Playgroud)