我有绘制到 html5 画布的 Renderer 类,我希望它在调整窗口大小时重绘内容。问题是 update() 代码只执行一次 - 在 initialize() 内 - 并且调整窗口大小不会做任何事情。另一方面,每次调整窗口大小时都会执行 onWindowResized() 。那么,错在哪里呢?
/// <reference path="../lib/easeljs.d.ts" />
/// <reference path="../lib/tweenjs.d.ts" />
/// <reference path="../lib/soundjs.d.ts" />
/// <reference path="../lib/preloadjs.d.ts" />
class Renderer
{
private mStage:createjs.Stage;
private mShape:createjs.Shape;
public initialize (stage:createjs.Stage):void
{
this.mStage = stage;
this.mStage.autoClear = true;
this.update ();
window.onresize = this.onWindowResized;
}
public update ():void
{
if (this.mStage)
{
this.mStage.canvas.width = window.innerWidth;
this.mStage.canvas.height = window.innerHeight;
this.mShape = new createjs.Shape();
this.mShape.graphics.beginFill("#dddddd");
this.mShape.graphics.drawRect(0, 0, this.mStage.canvas.width, this.mStage.canvas.height);
this.mShape.graphics.beginFill("#ff4400");
this.mShape.graphics.drawCircle(this.mStage.canvas.width / 2, this.mStage.canvas.height / 2, 25);
this.mStage.addChild(this.mShape);
this.mStage.update();
}
}
private onWindowResized (event:UIEvent):void
{
this.update();
}
}