-
How to make spinning object and easing stop.
Hello everyone.
I am trying to make star spinning (mouse cursor rollover the star, it would be change direction. and if click the star, it would spin start spin slowly and getting faster and then it would be easing stop.)
here is the my action script3.0
Please help me and I will really appreciate.
Thank you very much.
stop();
import flash.events.MouseEvent;
star.addEventListener(MouseEvent.MOUSE_DOWN, mouseClick);
function mouseClick (evt:MouseEvent)
{
play();
}
import flash.events.MouseEvent;
stage.addEventListener(MouseEvent.CLICK, clickStage);
function clickStage(event:MouseEvent):void{
star.rotation += rotationSpeed;
}
var rotationSpeed:Number = 10;
stage.addEventListener(Event.ENTER_FRAME, updateMouse);
function updateMouse(event:Event):void {
star.rotation += mouseX;
}
stop();
//mine is never stop... keep spinning...
-
This doesn't do everything you want, but might help you move in the right direction?
(i reorganized your code example a bit, then added some things which are explained in the comments)
Actionscript Code:
stop();
import flash.events.MouseEvent;
star.addEventListener(MouseEvent.MOUSE_DOWN, mouseClick); star.addEventListener(MouseEvent.MOUSE_OVER, onHover); stage.addEventListener(MouseEvent.CLICK, clickStage); stage.addEventListener(Event.ENTER_FRAME, updateMouse);
var rotationSpeed:Number = 1; //I set this to zero so it starts with no effect var spinDirection:Number = 1; //this is only ever set to "+1" or "-1", and is multiplied against rotationSpeed to determine if we're rotating clockwise or counterclockwise
function mouseClick (evt:MouseEvent):void{ // So your star MC has frames? that you want to play? (if not, then i'd delete this function altogether) evt.target.play(); //added "evt.currentTarget" to try and give Flash some idea of what should be playing. }
function onHover(evt:MouseEvent):void{ // when you rollover the star, change direction of spin spinDirection = spinDirection * -1; //toggles negative to positive, or vice versa }
function clickStage(event:MouseEvent):void{ //this happens anytime you click ANYWHERE on stage... rotationSpeed = 10; //everytime you click anywhere, this "speed of spinning" is set to it's maximum. //...might want to use larger number than 10 } function updateMouse(event:Event):void { //this happens EVERY frame no matter what... so, poorly named function? star.rotation += rotationSpeed * spinDirection; if(rotationSpeed >0) //this check will keep you from ever going below 0 rotationSpeed--; //this way the speed of spinning will fall off over time. }
* you mentioned wanting to speed up when the star is clicked, then ease off. but the quick code above would not do this exactly. it would just start at top speed, and slow down every frame, when you click anywhere in the stage.
(you could add another variable, maybe a boolean called "rising", which is checked to decide if you are speeding up, or easing off. in your ENTER_FRAME handler, you could add to rotationSpeed if rising is true, or subtract from rotationSpeed if rising is false. you could also have an if statement that says when rotationSpeed reaches a certain number, then switch rising from true to false. you'd also need to reset rising to true when you click to start the spin)
* might be worth looking into the tween() function.
hope this helps.
Last edited by warrenEBB; 02-23-2012 at 04:30 PM.
-
Thank you so much
Thank you so much I am really appreciated for replying my posting.
It is super helpful to me.
I change the "rotation speed = 300" so it makes feel more spinning.
Now, I am just trying to find easing stuff so when spin is stop, star will stop more smoothly.
Anyway Thank you so much!!!!
-
Change this
if(rotationSpeed >0) //this check will keep you from ever going below 0
rotationSpeed--; //this way the speed of spinning will fall off over time.
}
to
if(rotationSpeed >0.1) //this check will keep you from ever going below 0
rotationSpeed*=0.97; //this way the speed of spinning will fall off over time.
}else{
rotationSpeed = 0;
}
if you don't force it to be set to 0 when it falls past a certain point than it won't really ever stop.
Also you can do the same in reverse, just use a boolean to determine if you want it to go up or down.
Last edited by swak; 02-25-2012 at 03:06 AM.
.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|