Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

flash page flip

Actionscript 3.0 video tutorials

+ Reply to Thread
Results 1 to 3 of 3

Thread: Animation with Flash CS3 - spring friction and gravity

  1. #1
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,609
    Rep Power
    9

    Animation with Flash CS3 - spring friction and gravity

    flash templates
    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 !

  2. #2
    Junior Member Settled In bhatushai is on a distinguished road
    Join Date
    Feb 2008
    Posts
    7
    Rep Power
    0

    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?

  3. #3
    Junior Member Settled In dhanarajesh1 is on a distinguished road
    Join Date
    Nov 2008
    Posts
    1
    Rep Power
    0

    Re: Animation with Flash CS3 - spring friction and gravity

    Good site you has made
    http://www.saranamayyappamovie.com/ - 3D Animation Movie on Lord Ayyappa

+ Reply to Thread

LinkBacks (?)


Similar Threads

  1. Loading a flash animation
    By lucifier27 in forum Flash English
    Replies: 2
    Last Post: 28-09-09, 12:34
  2. Replies: 1
    Last Post: 15-10-08, 11:44
  3. Animazioni con Flash CS3 - spring e frizione
    By Flep in forum Articoli e tutorials
    Replies: 2
    Last Post: 27-04-08, 22:50
  4. Replies: 2
    Last Post: 24-03-08, 07:53
  5. Animazioni con Flash CS3 - the spring
    By Flep in forum Articoli e tutorials
    Replies: 0
    Last Post: 19-09-07, 14:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts