Gravity script (vishnubhatla)

  • vishnubhatla
  • Newbie
  • Newbie
  • vishnubhatla
  • Posts: 11

Post 3+ Months Ago

Hi Professionals,

I have learn gravity animation for ball,

I have write total code,

var ball1:ball=new ball();
addChild(ball1);
ball1.x=30;
ball1.y=300;
var gravity:Number=0.00098;
var dx:Number=0.2;
var dy:Number=-0.8;
var i=0;
var lastTime:int=getTimer();
addEventListener(Event.ENTER_FRAME,upper);
function upper(event:Event)
{
var timeDiff:int=getTimer()-lastTime;
lastTime+=timeDiff;
dy+=gravity*(getTimer()-(getTimer()*i));
ball1.x+=dx*timeDiff;
ball1.y+=dy*timeDiff;
if(ball1.y>=300){
ball1.y=300;
dy=-0.8;
timeDiff=timeDiff-getTimer();
i=i+1;
}
}


I got it!

try it, It's cool


Thanks,
K Swamy Vishnubhatla,

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 17 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.