LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 




 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-09-2009, 06:58 PM
codeoverride codeoverride is offline
Registered User
 
Join Date: May 2007
Posts: 15
Rep Power: 0
codeoverride is on a distinguished road
Games Follow Mouse (only in certain area)?

I have this red hanging lamp on my website and want it to swing either left or right depending on what side the mouse rolls over from so that it looks like the mouse gave it a small push. You can download the file I'm working on here: www.geocities.com/imagocreative/lamp.fla

I found a script for a pendulum that was posted a while back and tried to adapt it to my lamp but haven't been very successful yet. This is the script that I'm using:

/*
We need the function that will move our lamp. Basically,
we have a parameter t that represents the time. We increment this on
each frame to simulate time going forward. We put this value of time
into our sine function, and then we mutliply by our scale factor a,
whic represents the amplitude of the swing, and by another factor d,
which will dampen the oscillation once we mouse off.
*/

function swinglamp(p:MovieClip) {
//Apply our swing formula;
var rot:Number = p.a * p.d * Math.sin(p.t);
//Now set the rotation t this value;
p._rotation = rot;
//Increment the time;
p.t += Math.PI / p.speed;
}

/*
Now we need the onRollOver event;
*/

lamp.onRollOver = function() {
//We need to give the lamp some inital parameters;
//Amplitude (in degrees):
this.a = 10;
//The speed of oscillation (the bigger the number, the slower the oscillations);
this.speed = 8;
//Set the time;
this.t = 0;
//Set the damping (initally no damping, so set to 1);
this.d = .5;
//Set the onEnterFrame to our swinglamp function;
this.onEnterFrame = function() {
swinglamp(this);
}
}

/*
And then for the RollOut, all we do is slowly decrease the value of d.
Once d falls below zero, we delete the onEnterFrame to save memory;
*/

lamp.onRollOut = function() {
this.onEnterFrame = function() {
swinglamp(this);
//To make the lamp slow down more quickly, decrease this number (but not by a lot!)
this.d *= 0.90;
//Test to see if d < 0;
if (this.d < 0) {
this._rotation = 0;
delete this.onEnterFrame;
}
}
}

Last edited by codeoverride : 10-10-2009 at 10:41 AM
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Movieclip to follow mouse dalton Newbies 0 10-17-2008 02:42 PM
how to get somthing to follow the mouse at different speeds! wildweelz Flash MX 2004 1 09-21-2007 03:04 AM
mouse follow without easing maverick_xj Actionscript 2.0 4 09-13-2004 12:16 PM
how do i make a movie object follow the mouse? a7ay General Flash 3 11-10-2003 11:45 PM
follow mouse direction damn Flash 5 Actionscript 8 05-29-2001 10:07 PM




All times are GMT. The time now is 05:14 AM.