ActionScript - Automatic containment and repositioning of object bounds

Posted by TheDarkIn1978 on Stack Overflow See other posts from Stack Overflow or by TheDarkIn1978
Published on 2010-04-14T19:09:03Z Indexed on 2010/04/14 19:13 UTC
Read the original article Hit count: 162

Filed under:
|
|

when adding objects arbitrarily to the stage with mouse clicks, is there a more simple way to making sure the object's bounds do not exceed those of the stage?

currently i'm calling something like this before adding the object to the display list:

var newSwatchRect:Rectangle = newSwatch.getBounds(this);
if (newSwatchRect.x < stage.x) {newSwatchRect.x = stage.x;}
if (newSwatchRect.y < stage.y) {newSwatchRect.y = stage.y;}
if (newSwatchRect.x + newSwatchRect.width > stage.stageWidth) {newSwatchRect.x = stage.stageWidth - newSwatchRect.width;}
if (newSwatchRect.y + newSwatchRect.height > stage.stageHeight) {newSwatchRect.y = stage.stageHeight - newSwatchRect.height;}

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about contains