Adding Bitmap and Text into Container

186 views
Skip to first unread message

Oren Shvalb

unread,
Dec 21, 2015, 11:17:56 PM12/21/15
to CreateJS Discussion
Hi,

I have a question regarding adding items to Container.

I have the following code:

var scheduled_item = new createjs.Bitmap(preloader.getResult("scheduled_item_img"));

var item_timer_text = new createjs.Text("Hello World", "20px Arial", "#ff7700");
item_timer_text
.x = scheduled_item.width / 2;
item_timer_text
.y = scheduled_item.height+50;

var scheduled_item_container = new createjs.Container();
scheduled_item_container
.addChild(scheduled_item, item_timer_text);

stage
.addChild(scheduled_item_container);
stage
.update();


When I run this code I do see the image and the text, BUT - I can't seem to move the text under the image.
it's like totally ignores my x,y settings of the text item.

Any idea how to set it right?

fumio

unread,
Dec 22, 2015, 12:03:12 AM12/22/15
to CreateJS Discussion
The Bitmap class has no width nor height properties.  How about using the Bitmap.getBounds() method.  Or you should get width and height values from the Image object passed to the Bitmap() constructor.

2015年12月22日火曜日 13時17分56秒 UTC+9 Oren Shvalb:

Oren Shvalb

unread,
Dec 22, 2015, 12:18:50 AM12/22/15
to CreateJS Discussion
I tried adding boundaries to both Bitmap and Text, but still can't get the text item under the bitmap.

var scheduled_item = new createjs.Bitmap(preloader.getResult("scheduled_item_img"));

scheduled_item.setBounds(0,0, 300,300);

var item_timer_text = new createjs.Text("Hello World", "20px Arial", "#ff7700");
item_timer_text.setBounds(
 item_timer_text
.x = scheduled_item.width / 2,
 
250,
 
200,
 
30
 
);


var scheduled_item_container = new createjs.Container();
scheduled_item_container
.addChild(scheduled_item, item_timer_text);

stage
.addChild(scheduled_item_container);
stage
.update();



but still not working.

fumio

unread,
Dec 22, 2015, 3:02:30 AM12/22/15
to CreateJS Discussion
The setBounds() method does not make sense to use.  It does not create the width and height properties into the DisplayObject nor change its appearance.  Read "Update: Width & Height in EaselJS".

2015年12月22日火曜日 14時18分50秒 UTC+9 Oren Shvalb:

Oren Shvalb

unread,
Dec 22, 2015, 9:20:29 AM12/22/15
to CreateJS Discussion
Thank you! I will check how to use getBounds().
Reply all
Reply to author
Forward
0 new messages