lundi 13 février 2017

MovieClip Y position becomes negative on update loop using delta time

I am coding a game in flash AS3 and I have implemented my game loop using the answer provided here: Is this a good implementation of the gameloop However, after increasing my movieclip's y position by dist (dist is from speed * timeElapsed) the movieclip's y position becomes negative. I have noticed this negative value by tracing the movieclips position on each update.

See code: global variable declaration:

var speed:Number = 250;
var balls:Array = [];
private var _lastTime:Number = 0;

public function loop(e:Event):void
{
    var now = new Date().getTime();
    var _delta = now - _lastTime;
    _lastTime = now;
    updateGameState(_delta/1000); //convert delta to seconds
}

public function updateGameState(timeElapsed:Number):void
{
    var dist:Number = speed * timeElapsed;
    balls[0].y += dist;
    trace(balls[0].y);
}

I would like to know what is causing this sudden negative value of movieclips y position.

Aucun commentaire:

Enregistrer un commentaire