12-31-2010 09:56 AM
hi
How to set background image to container.
Solved! Go to Solution.
12-31-2010 10:43 AM
Create an image the size of the container, add it to the container, and then set the image to the source file. If the image is already the size of the container, then you dont have to set the image size.
PsedoCode:
var bgimage : Image = new Image(); mycontainer.addChild( bgimage ); bgimage.setImage( 'assets/bg.jpg' );
If the image is embedded, the your setImage will allocated to that embedded image.
If the image is in another directory, other than your source directory, then that would be different.
12-31-2010 10:55 AM
Hey,
Do we always have to put the background image in a container?
I have it on the main sprite, and then I just overlay/add new items on top of it.
i.e.
addChild(bgimage)
addChild(button)
addChild(title)
Since bgimage is added first, everything else just goes on top.
Is there a reason why people use containers? I find no use for them really but maybe its just my app.
I just put everything relative to an x and y coordinate.
Thanks.
12-31-2010 11:20 AM
People use containers when they want a "fluid" layout, where items move around automatically to "reasonable" places without you having to manually set the position of each one. This can have benefits in terms of reducing coding time, improving consistency of appearance, and more easily supporting automatic orientation adjustment (flip between portrait/landscape).
Depending on the apps, containers can either be very helpful, useless, or somewhere in between. Your choice. Best to learn a bit about them, then decide for yourself.