user1482015
user1482015

Reputation:

Easeljs, is it a recommend way to fix the size of container?

Maybe I am wrong, I learn Easeljs for a week only.
The Container has no width and height to set the size.

I have 2 questions:
1. is the size of Container, dynamically change with the child.
2. if question 1 answer is yes, can I add a big bitmap or shape to it, eg. a background image...etc. to control the size of Container?

Upvotes: 2

Views: 2122

Answers (2)

Lanny
Lanny

Reputation: 11294

Consider a container as a group of objects, not a physical container. Containers give you the ability to transform, translate, cache, and otherwise control multiple items as a single item. They do not really have a physical size, except that of their collective children.

There is no width or height mainly due to the cost of calculating the size, especially considering transformations, sub-containers, etc. There may be support added in the future for width/height, but for now its not available.

[UPDATE]: Containers do have bounds, based on the bounds of children (retrieved using container.getBounds() (docs) that have bounds. For example, a Container that has Sprite, Bitmap, Text, objects with manually set bounds, or cached DisplayObjects will report bounds using those children. Shapes do not have auto-calculated bounds currently, so will not contribute to container bounds.

Upvotes: 2

supersan
supersan

Reputation: 6141

This is a very bad hack, but if you absolutely must fix the size of the container, you can use something like this:

var blank = new createjs.Shape();
var width = 1;
var height = 400;
blank.setBounds(0, 0, width, height);
container.addChild(blank);

This will set the size of container to the blank image and now any background you draw on it will be visible.

Upvotes: 2

Related Questions