我完全迷失在EaslJS中。当我的函数被调用时,我无法弄清楚如何调整矩形的大小。在EaselJS中调整矩形的大小
情景是这样的:我的玩家被击中,健康状况下降,因此健康状况变得更小。
下面是如何创建healthbar:
this.statusBar = new createjs.Shape()
this.statusBar.graphics
.beginFill("red")
.drawRect(0, 0, this.width, this.height);
this.statusBar.x = this.x+500;
this.statusBar.y = this.y;
this.statusBar.width = this.width;
this.statusBar.height = this.height;
而这正是我试图调整其大小:
this.decreaseHealth = function(amount) {
percentageLeft = (player.health/player.fullPlayerHealth)*100;
console.log(this.fullBarWidth*(percentageLeft/100));
this.statusBar.width = this.fullBarWidth*(percentageLeft/100);
}
我stage.update();
是我的循环,所以它更新的方式你可能会期待。
代码是正确的,但是你能否改变术语“容器” - 它可能与'createjs.Container'混淆,其中'Shape'不会从中继承:) – olsn 2013-03-26 21:30:54
@olsn:可能是一个好点;)编辑为称Shape对象是绘图控制器而不是容器。 – markE 2013-03-26 22:05:10