Created
February 23, 2012 20:13
-
-
Save ain/1894840 to your computer and use it in GitHub Desktop.
AS3 visible bounds of DisplayObject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package { | |
import flash.display.Sprite; | |
import flash.display.Graphics; | |
import flash.geom.Rectangle; | |
import flash.geom.PerspectiveProjection; | |
import flash.display.BitmapData; | |
public class PPPlane extends Sprite { | |
public function PPPlane():void { | |
var Plane:Sprite = drawPlane(); | |
Plane.x = (stage.stageWidth - Plane.width) * 0.5; | |
Plane.y = (stage.stageHeight - Plane.height) * 0.5; | |
Plane.z = 100; | |
Plane.rotationY = 70; | |
Plane.rotationX = 20; | |
Plane.rotationZ = 30; | |
addPerspective(); | |
addChild(Plane); | |
trace("Plane size: "+Plane.width+"x"+Plane.height); | |
var bounds:Rectangle = Plane.getBounds(stage); | |
trace("Plane bounds: "+bounds); | |
var visibleBounds:Rectangle = visibleBitmapBounds(); | |
trace("Visible, on-screen bounds of the Plane: "+visibleBounds); | |
} | |
private function addPerspective():void { | |
var pp:PerspectiveProjection = new PerspectiveProjection(); | |
pp.fieldOfView = 120; | |
this.transform.perspectiveProjection = pp; | |
} | |
private function drawPlane():Sprite { | |
var Plane:Sprite = new Sprite(); | |
Plane.graphics.beginFill(0x0000FF); | |
Plane.graphics.drawRect(0, 0, 200, 200); | |
Plane.graphics.endFill(); | |
return Plane; | |
} | |
private function visibleBitmapBounds():Rectangle { | |
var w:int = stage.stageWidth; | |
var h:int = stage.stageHeight; | |
var bitmapData:BitmapData = new BitmapData(w, h, true, 0); | |
bitmapData.draw(this) | |
var bounds:Rectangle = bitmapData.getColorBoundsRect(0xFF000000, 0x00000000, false); | |
bitmapData.dispose(); | |
return bounds; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gist from ActionScript 3 lacks functionality for visible bounds of DisplayObject on flash tekkie.