【发布时间】:2014-02-24 11:06:33
【问题描述】:
在这段代码JSFiddle Code 中,我尝试在舞台上放置一个大容器。这个大容器还有另外 2 个容器,每个容器都包含一个形状。 我想看舞台上的形状,但我做不到。 编译器不会抛出任何错误。
这是我写的代码:
// CREATE STAGE //
var stage = new createjs.Stage("myCanvas");
// CREATE TIME_CONTAINER //
var time_container = new createjs.Container();
time_container.x = stage.x;
time_container.y = stage.y;
time_container.width = stage.width;
time_container.height = stage.height;
// CREATE DEV CONTAINER //
var dev_container = new createjs.Container();
dev_container.x = time_container.x;
dev_container.y = time_container.y;
dev_container.width = time_container.width / 2;
dev_container.height = time_container.height;
var dev_shape = new createjs.Shape();
dev_shape.graphics.beginFill("#ff0000").drawRect(dev_container.x,dev_container.y,dev_container.width,dev_container.height);
// CREATE PLAYER CONTAINER //
var player_container = new createjs.Container();
player_container.x = time_container.width / 2;
player_container.y = time_container.y;
player_container.width = time_container.width / 2;
player_container.height = time_container.height;
var player_shape = new createjs.Shape();
player_shape.graphics.beginFill("#ff0000").drawRect(player_container.x,player_container.y,player_container.width,player_container.height);
// ADD TIME_CONTAINER TO THE STAGE //
stage.addChild(time_container);
time_container.addChild(dev_container,player_container);
dev_container.addChild(dev_shape);
player_container.addChild(player_shape);
stage.update();
【问题讨论】:
-
stage.width 和 height 未定义!
-
@ProllyGeek 我有这样的画布 我还需要定义如果我从已经有宽度和高度的画布上创建它?
-
不,你刚刚错过了 stage.canvas.width;和stage.canvas.height; ,仅此而已
标签: javascript html containers shapes easeljs