Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

Animation with Flash CS3 - spring friction and gravity

This is a discussion on Animation with Flash CS3 - spring friction and gravity within the Tutorials forums, part of the Flash English category; This article carries on the series started with inertia effect . We saw next how to add the spring effect and ...


Go Back   Forum Flash CS3 Flash CS4 > Flash CS3 Flash CS4 > Flash English > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-10-07, 07:01
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
Animation with Flash CS3 - spring friction and gravity

This article carries on the series started with inertia effect.
We saw next how to add the spring effect and the friction effect.
Now, we will see the gravity and how to bounce a ball.

Follow me"







I create a FLA and save it as "gravita.fla".
Into which, I place on stage a circular MovieClip named "ball_mc".

Here is the code:
Code:
var spring:Number=.1;
var frizione:Number=.98;
var gravita:int=1;
var limite:Number=stage.stageHeight;

stage.frameRate=31;

ball_mc.velY=0;
ball_mc.oldY=0;
ball_mc.addEventListener(Event.ENTER_FRAME,go);

function go(e:Event):void
{
	e.target.velY+=gravita;
	e.target.velY*=frizione;
	e.target.y+=e.target.velY;
	if(e.target.y>limite-e.target.width/2)
	{
		e.target.y=limite-e.target.width/2;
		e.target.velY*=-1;
	}
}
Let us analyse the code

Four numerical variables which respectively contains the needed values for the effect
var spring:Number=.1;
var frizione:Number=.98;
var gravita:int=1;
var limite:Number=stage.stageHeight;
I impost the frame rate
stage.frameRate=31;
I assign two properties to "ball_mc" (the speed)
ball_mc.velY=0;
ball_mc.oldY=0;
I add ENTER_FRAME which calls the function "go"
ball_mc.addEventListener(Event.ENTER_FRAME,go);
function go(e:Event):void
{
I add the gravity to "velY" (a property assigned to "ball_mc" with an initial value equal to zero)
e.target.velY+=gravita;
I add the friction
e.target.velY*=frizione;
I add to ball_mc"s y the property "velY"
e.target.y+=e.target.velY;
I check the ball_mc"s y
if(e.target.y>limite-e.target.width/2)
{
if it is bigger then the value of the variable "limite" less half of "ball_mc" width I invert the value of "velY"
e.target.y=limite-e.target.width/2;
e.target.velY*=-1;
}
}

Stay tuned !
__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !

Last edited by Flep; 28-08-08 at 06:39..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 18-03-08, 06:23
Junior Member
 
Join Date: Feb 2008
Posts: 5
Rep Power: 0
bhatushai is on a distinguished road
Re: Animation with Flash CS3 ? spring friction and gravity

how to reversed the gravity making the ball floating?or need to add a few codes more?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 14-11-08, 12:09
Junior Member
 
Join Date: Nov 2008
Posts: 1
Rep Power: 0
dhanarajesh1 is on a distinguished road
Re: Animation with Flash CS3 - spring friction and gravity

Good site you has made
__________________
http://www.saranamayyappamovie.com/ - 3D Animation Movie on Lord Ayyappa
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
Animations with flash CS3 - spring and friction + mouse Flep Tutorials 1 15-10-08 12:44
Animazioni con Flash CS3 - spring e frizione Flep Articoli e tutorials 2 27-04-08 23:50
Animations with Actionscript 3.0 - spring and friction Flep Tutorials 2 24-03-08 08:53
Animazioni con Flash CS3 - spring su 3 punti Flep Articoli e tutorials 0 20-09-07 14:24
Animazioni con Flash CS3 - the spring Flep Articoli e tutorials 0 19-09-07 15:58


All times are GMT. The time now is 13:41.

Powered by vBulletin version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap