Note that there are some explanatory texts on larger screens.

plurals
  1. POActionScript applying rotation of sprite to startDrag()'s rectangle bounds
    text
    copied!<p>from my main class i call to create a sprite and add it to the stage</p> <pre><code>private function addSwatch(evt:MouseEvent):void { if (stage.getObjectsUnderPoint(mousePoint()).length == 0) { var swatchSide:Number = 100; var newSwatch:Sprite = new Swatch(0 - swatchSide/2, 0 - swatchSide/2, swatchSide, swatchSide); newSwatch.x = mouseX; newSwatch.y = mouseY; addChild(newSwatch); } } </code></pre> <p>i've added a swatch sprite to the stage which, when dragged, is contained within set boundaries.</p> <pre><code>this.startDrag(false, swatchBounds()); ... private function swatchBounds():Rectangle { var stageBounds = new Rectangle ( 0 - defaultSwatchRect.x, 0 - defaultSwatchRect.y, stage.stageWidth - defaultSwatchRect.width, stage.stageHeight - defaultSwatchRect.height ); return stageBounds; } </code></pre> <p>if the square sprite is scaled, the following returned rectangle boundary works</p> <pre><code>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; } </code></pre> <p>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</p> <pre><code>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; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload