ActionScript rotated sprite's startDrag bounds
Posted
by TheDarkIn1978
on Stack Overflow
See other posts from Stack Overflow
or by TheDarkIn1978
Published on 2010-04-10T20:25:39Z
Indexed on
2010/04/10
20:33 UTC
Read the original article
Hit count: 584
when assigning a bounds to a draggable sprite, it doesn't seem to take rotation of the sprite into consideration.
the code below adds a sprite to the display list, rotates it 45º, and adds a MouseEvent.MOUSE_DOWN event to allow dragging.
the startDrag() method's second parameter simply returns the bounds of the stage as a rectangle. however, because of the sprite's rotation, its corners can be dragged past the bounds of the stage.
any thoughts?
var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0x0000FF, 1);
mySprite.graphics.drawRect(0, 0, 200, 200);
mySprite.graphics.endFill();
mySprite.rotation = 45;
addChild(mySprite);
mySprite.addEventListener(MouseEvent.MOUSE_DOWN, dragSprite, false, 0, true);
function dragSprite(evt:MouseEvent):void
{
evt.target.startDrag(false, spriteBounds());
}
© Stack Overflow or respective owner