APE Project - Step 6 - Rotating Rectangle Particles
No commentsI’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 );
}
Wednesday, August 13th, 2008 at 10:14 am and is filed under APE - Actionscript Physics Engine, Actionscript 3. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.