倒计时和积分,AS3

时间:2010-06-25 08:23:01

标签: flash actionscript

这一切都很完美,但有一点。我现在如何计算? 感谢

生命损失的输出
580 560 540 520 500 480 460 等...

输出需要
600 599 598 597 596 595 等等......如果没有胜利,则以时间结束为止

屏幕截图

alt text http://poizenpoprecords.com/myspace/videodnd/deltaTime.jpg

的ActionScript

//Starts with 600 life points, counts from 30-0
//game will be more intricate and retotal scores, this is just a sketch
var EQUATION:int;
var TIME:int = 30;
var COUNTDOWN:Number = 600;
var COUNTUP:Number = 0;
var START:int = getTimer();
var DELTATIME:int;
var lucky:int;

var myTimer:Timer = new Timer(1000,30);
myTimer.addEventListener(TimerEvent.TIMER,someFunction);
myTimer.start();

function someFunction(event:TimerEvent) {
DELTATIME = (getTimer() - START)/1000;
//trace(DELTATIME);
//lucky = Math.floor(Math.random()*55);
//trace(lucky);
EQUATION = COUNTDOWN - (DELTATIME*COUNTDOWN/TIME) + COUNTUP; 
var str:String = String (Math.abs (EQUATION));
//var sub:String = ("000000")+ str.substr(0, 4);
//tx.text = String (sub);
tx.text = String ("YOU HAVE  ")+(EQUATION)+("  POINTS");
txt.text = String(Math.floor(30 - DELTATIME))+("  SECONDS LEFT");
trace(EQUATION);
if(lucky==16){
myTimer.stop(); 
var mtInter:uint = setInterval (blk, 222);
function blk():void {
txt.visible = !txt.visible;
tx.visible = !tx.visible;
txt.text = String("You're Lucky This Time");
tx.text = String("You Get 100 Life Points!");
}
}
if(EQUATION==0){
myTimer.stop(); 
var mtIntv:uint = setInterval (blink, 222);
function blink():void {
txt.visible = !txt.visible;
tx.visible = !tx.visible;
txt.text = String("Time's Up!");
tx.text = String("You're Dead!");
}
}
}

赢得胜利

1 个答案:

答案 0 :(得分:1)

您的更新功能仅每秒调用一次,因此最多可以显示30个值。您希望计时器至少为每个生命点调用一次更新功能。你也使用了一个int作为DELTA值,它将数字向下舍入到最接近的整数。将其更改为类型数字让你得到小数。

以下是您的代码已更新为1,但现在您的幸运函数将更频繁地计算,因此您需要对其进行调整:

    //Starts with 600 life points, counts from 30-0
//game will be more intricate and retotal scores, this is just a sketch
var EQUATION:int;
var TIME:int = 30;
var COUNTDOWN:Number = 600;
var COUNTUP:Number = 0;
var START:int = getTimer();
var DELTATIME:Number;//<-- Changed this to a Number to you get more than 30 values out of it
var lucky:int;

var myTimer:Timer = new Timer(25); //<-- Changed the timer to repeat every 25 milliseconds and infinitely
myTimer.addEventListener(TimerEvent.TIMER,someFunction);
myTimer.start();

function someFunction(event:TimerEvent) {
DELTATIME = (getTimer() - START)/1000;
//trace(DELTATIME);
//lucky = Math.floor(Math.random()*55);
//trace(lucky);
EQUATION = COUNTDOWN - (DELTATIME*COUNTDOWN/TIME) + COUNTUP; 
var str:String = String (Math.abs (EQUATION));
//var sub:String = ("000000")+ str.substr(0, 4);
//tx.text = String (sub);
tx.text = String ("YOU HAVE  ")+(EQUATION)+("  POINTS");
txt.text = String(Math.floor(30 - DELTATIME))+("  SECONDS LEFT");
trace(EQUATION);
if(lucky==16){
myTimer.stop(); 
var mtInter:uint = setInterval (blk, 222);
function blk():void {
txt.visible = !txt.visible;
tx.visible = !tx.visible;
txt.text = String("You're Lucky This Time");
tx.text = String("You Get 100 Life Points!");
}
}
if(EQUATION==0){
myTimer.stop(); 
var mtIntv:uint = setInterval (blink, 222);
function blink():void {
txt.visible = !txt.visible;
tx.visible = !tx.visible;
txt.text = String("Time's Up!");
tx.text = String("You're Dead!");
}
}
}