Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

_rotation question 1

Status
Not open for further replies.

dwnhllr

IS-IT--Management
Aug 12, 2003
14
US
I am trying to get a drawn movie clip to rotate to match the movement of the mouse. Here's a silly example that demonstrates what I'm trying to do (without pasting my whole actionscript module):


movieclip.prototype.drawexample = function(sx,sy,fx,fy){
var angle = Math.atan2(sy-fy,sx-fx)*(180/Math.PI);
if (this.Depth == undefined) {
this.Depth = this.getDepth();
}
var t = this.createEmptyMovieClip ("somesymbol"+this.Depth+"_mc", this.Depth);
t.moveto(sx,sy);
t.lineto(15,0); // draw a line along the x-axis
t._rotation = angle; // rotate the line to the mouse pos
}

_root.onMouseMove = function(){
clip.unloadMovie();
clip = drawexample(0,0,_root._mousex,_root.mousey);
}

Shouldn't the clip rotate to the mouse position?
 
oops... I forgot to put the final line in the "drawexample" function:

return t;
 
i cant get the code to draw anything

however

clip = drawexample(0,0,_xmouse,_ymouse);

at least gets values for the x and y mouse positions

by quickly messing with your code i got this to draw and rotate with a blank movie(clip)

Code:
movieclip.prototype.drawexample = function(sx,sy,fx,fy){movieclip.prototype.drawexample = function(sx,sy,fx,fy){
  var angle = Math.atan2(sy-fy,sx-fx)*(180/Math.PI);
  if (this.Depth == undefined) {
        this.Depth = this.getDepth();
  }
   duplicateMovieClip(_root.clip,"clip1",1);
	with (clip){
		lineStyle (1, 0xFF0000, 100);
		moveTo (sx, sy);
		lineTo (100, 300);	
		_rotation = angle;
}
return clip
}

_root.onMouseMove = function(){
  clip.unloadMovie();
  clip.drawexample(0,0,_xmouse,_ymouse);
}

  var angle = Math.atan2(sy-fy,sx-fx)*(180/Math.PI);
  if (this.Depth == undefined) {
        this.Depth = this.getDepth();
  }
   duplicateMovieClip(_root.clip,"clip1",1);
	with (clip){
		lineStyle (1, 0xFF0000, 100);
		moveTo (sx, sy);
		lineTo (100, 300);	
		_rotation = angle;
}
return clip
}

_root.onMouseMove = function(){
  clip.unloadMovie();
  clip.drawexample(0,0,_xmouse,_ymouse);
}
 
Here's my take on it - the problem was the way you were reading the mouse position properties...

Code:
movieclip.prototype.drawexample = function(sx, sy, fx, fy) {
	var angle = Math.atan2(sy-fy, sx-fx)*(180/Math.PI);
	if (this.Depth == undefined) {
		this.Depth = this.getDepth();
	}
	var t = this.createEmptyMovieClip("somesymbol"+this.Depth+"_mc", this.Depth);
	//red line
	t.lineStyle(1, 0xcc0000, 100);
	t.moveto(sx, sy);
	t.lineto(15, 0);
	t._rotation = angle;
	//smooth out the motion by updating the screen only when the event fires
	updateAfterEvent();
};
//
this.onMouseMove = function() {
	clip.unloadMovie();
	//your mouse position calls were wrong, should be...
	clip = drawexample(0, 0, _xmouse, _ymouse);
};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top