开发者

acceleration ramp "increments" for Counter AS3

My counter goes to 100 at a constant speed. I开发者_如何学Gos there a way to ramp the speed of a counter?

Flash can use trigonometry values to effect speed, but I don't know if that can change the timer class on-the-fly.

There's a couple parts to it.

(a.) ramp the speed of a counter?

(b.) ramp in certain parts?

- have a range

- 90-100 starts ramping

either example of trigonometry of increments would be helpful

alt text http://www.ashcraftband.com/myspace/videodnd/icon10.jpg

TRIG EXAMPLE I WANT TO APPLY

var xVel:Number = Math.cos(radians) * speed;
var yVel:Number = Math.sin(radians) * speed;
//-------------------------------------------//
return deg * (Math.PI/180);

ACCELLERATING COUNTER "all good examples"

//EVERYONE HELPED "decimals corrected" 
var timer:Timer = new Timer(10);  
var count:int = 0; //start at -1 if you want the first decimal to be 0  
var fcount:int = 0; 

timer.addEventListener(TimerEvent.TIMER, incrementCounter);  
timer.start();  


function incrementCounter(event:TimerEvent) {  
  count++;  
  //
  fcount=int(count*count/10000);//starts out slow... then speeds up 
  //
  var whole_value:int = int(fcount / 100); //change value 
  var tenths:int = int(fcount / 10) % 10;   
  var hundredths:int = int(fcount) % 10; 

"thanks for spending the time to help"


Why don't you use one of the many ActionScript tweening engines such as TweenLite?

It can do all the math for you, you just need to give it what variable to interpolate, its final value, the total duration of the interpolation, and chose between the differents easing functions.

In some cases, if you need something really custom, you can just tween a Number variable from 0 to 1, with the duration & easing function you want to use, and then define an onUpdate function to let you do your work with this value, which will be interpolated through time.


You can get an simple approximation of a speeding-up effect by applying a formula to your count variable, like this:

var timer:Timer = new Timer(10); 
var count:int = 0; //start at -1 if you want the first decimal to be 0 
var fcount:int = 0;

timer.addEventListener(TimerEvent.TIMER, incrementCounter); 
timer.start(); 


function incrementCounter(event:TimerEvent) { 
  count++; 
  fcount=int(count*count/10000);//starts out slow... then speeds up 
  var whole_value:int = int(fcount/100); 
  var decimal_value:int = int(fcount/10) % 10;
  var hun_value:int = fcount % 10;
  mytext.text = whole_value + " : " + decimal_value + hun_value; 
} 

ie: count is increasing regularly, but fcount speeds up in proportion to the square of count.

If you want a trig function, you could try fcount=int(acos(count/10000)*10000/(2*Math.PI)); but this would only work for count<=10000.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜