I’ll have to finish this little piece up tomorrow, as it is not working properly at the moment. Ideally I want the user the ability to rotate the dynamically drawn rectangle by simply clicking the rectangle. I have found that the Rectangle Particle needs to be redrawn in order to edit the angle – you can actually rotate the object, but the collision detection with other objects does not stand true. So we will continue on until tomorrow.. for now, if you drag your mouse to draw the rectangle and then immediately click the rectangle, the object will rotate.
I just made some edits and additions to Main.as:
private function drawRectangle():void
{
if ( beginY < 660 && endY < 660 )
{
// store the data
_xpos = beginX + ( (endX - beginX)/2 );
_ypos = beginY + ((endY - beginY)/2);
_rwidth = endX - beginX;
_rheight = endY - beginY;
_rrotation = 0;
dynRect = new RectangleParticle(_xpos, _ypos, _rwidth, _rheight, _rrotation, true);
defaultGroup.addParticle(dynRect);
dynRect.sprite.addEventListener ( MouseEvent.MOUSE_DOWN, rotateRectangle );
}
}
private function rotateRectangle( m:MouseEvent ):void
{
// increment the angle
_rrotation += 5;
// rid of the particle
defaultGroup.removeParticle(dynRect);
// redraw the particle
dynRect = new RectangleParticle(_xpos, _ypos, _rwidth, _rheight, _rrotation, true);
defaultGroup.addParticle(dynRect);
dynRect.sprite.addEventListener ( MouseEvent.MOUSE_DOWN, rotateRectangle );
}
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.