
Math.ceil() Method
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
604
|
ActionScript Language Reference
rotateTowardsMouse( ), to all movie clips. It then assigns rotateTowardsMouse( ) to the
onEnterFrame( ) handler of the clip
triangle_mc, so that with every passing frame, the clip
rotates towards the mouse pointer. The same technique could be used to orient an enemy
spaceship toward a player’s spaceship.
// Convert radians to degrees. There are 2*pi radians per 360 degrees.
_global.radiansToDegrees = function (radians) {
return (radians/Math.PI) * 180;
}
// Method: MovieClip.rotateTowardsMouse()
// Desc: Rotates a clip's positive x-axis towards the mouse pointer.
MovieClip.prototype.rotateTowardsMouse = function () {
// Create a point object that stores the x- and y-coordinates of
// this clip relative to its parent's registration point.
var point = {x:this._x, y:this._y};
// Convert the clip's parent's local coordinates to global (Stage) coordinates.
this._parent.localToGlobal(point);
// Measure the distance between the registration
// point of this clip and the mouse.
var deltaX = _root._xmouse - point.x;
var deltaY = _root._ymouse - point.y;
// Calculate the angle of the line from the registration point
// of this clip to the mouse. Note that the y-coordinate is passed first.
var rotationRadian = Math.atan2(deltaY, deltaX); ...