【发布时间】:2012-11-28 22:47:28
【问题描述】:
有没有一种方便的方法可以在模块内访问全局变量,而不会出现编译器错误,即下面使用的 CANVAS_WIDTH?
export class Bullet {
x: number = 22;
y: number = 22;
constructor (speed: number) {
this.xVelocity = speed;
}
inBounds() {
return this.x >= 0 && this.x <= CANVAS_WIDTH &&
this.y >= 0 && this.y <= CANVAS_HEIGHT;
};
}
}
【问题讨论】:
-
您将在哪里设置 CANVAS_WIDTH 的值?
-
在游戏类中使用 Bullet 类导入模块 GameObjects = module("GameObjects")
-
您在 Game 类中有 CANVAS_WIDTH,需要在 Bullet 类中访问它。我说的对吗?
标签: typescript