PDA

View Full Version : graphic respond to left and right mouse movement



kmksunfire
08-12-2008, 05:05 PM
Hello,
I am making a fishing game, very simple. I need the fisherman to follow mouse arrow_Left to right. not up and down. I thought about making the fisherman replace the mouse arrow, and then somehow restricting up and down movement... But I would rather keep mouse arrow and just have fisherman respond. Does anybody know of a good location or code I could use?
Thanks

NTD
08-15-2008, 09:52 PM
Hi,

Turn your fisherman into a movieclip object and this will rotate the movieclip to the mouse position...


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);
// Convert the radian version of the angle to degrees.
var rotationAngle = radiansToDegrees(rotationRadian);
// See earlier function
// Update the rotation of this clip to point to the mouse.
this._rotation = rotationAngle;
}
this.onEnterFrame = function() {
_root.fisherman.rotateTowardsMouse();


Regards
NTD