I’m currently working on an actionscript game, and am trying to set stage boundaries; however, the player object is a subobject of a stage object; and when referencing player.x, I’m getting it’s x position within the level object itself. In essence, what I’m trying to do is;
if (player.x < stage.x.0) {
player.x = stage.x.0
}
Is there any easy way to do this, or should I simply make sure the player object is always on the stage, rather than as a subobject?
You can use the localToGlobal() method to convert a Point (flash.geom.Point) from one object’s coordinates to stage coordinates. Either by asking subobject to convert the player’s location:
Or, because a new Point is at 0, 0 by default, by asking the player object itself to convert that to global coordinates: