ActionScript applying rotation of sprite to startDrag()'s rectangle bounds

Posted by TheDarkIn1978 on Stack Overflow See other posts from Stack Overflow or by TheDarkIn1978
Published on 2010-04-13T03:05:57Z Indexed on 2010/04/13 3:13 UTC
Read the original article Hit count: 425

Filed under:
|
|
|
|

i've added a square sprite to the stage which, when dragged, is contained within set boundaries.

private function swatchBounds():Rectangle
 {
 var stageBounds = new Rectangle ( 
         0 - defaultSwatchRect.x,
         0 - defaultSwatchRect.y,
         stage.stageWidth - defaultSwatchRect.width,
         stage.stageHeight - defaultSwatchRect.height
         );
 return stageBounds;
 }

if the square sprite is scaled, the following returned rectangle boundary works

private function swatchBounds():Rectangle
 {
 var stageBounds = new Rectangle ( 
         0 - defaultSwatchRect.x * swatchObject.scaleX,
         0 - defaultSwatchRect.y * swatchObject.scaleY,
         stage.stageWidth - defaultSwatchRect.width * swatchObject.scaleX,
         stage.stageHeight - defaultSwatchRect.height * swatchObject.scaleY
         );
 return stageBounds;
 }

now i'm trying to include the square sprites rotation into the mix. math certainly isn't my forté, but i feel i'm on the write track. however, i just can't seem to wrap my head around it to get it right

private function swatchBounds():Rectangle
 {
 var stageBounds = new Rectangle ( 
         0 - defaultSwatchRect.x * swatchObject.scaleX * Math.cos(defaultSwatchRect.x * swatchObject.rotation),
         0 - defaultSwatchRect.y * swatchObject.scaleY * Math.sin(defaultSwatchRect.y * swatchObject.rotation),
         stage.stageWidth - defaultSwatchRect.width * swatchObject.scaleX * Math.cos(defaultSwatchRect.width * swatchObject.rotation),
         stage.stageHeight - defaultSwatchRect.height * swatchObject.scaleY * Math.sin(defaultSwatchRect.height * swatchObject.rotation)
         );
 return stageBounds;
 }

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about rotation