1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| public function initTemps()
{
this.estSelectionne = false;
this.peutAttaquer = false;
var tpsTimer:Number = 0;
//echelle correspond à 2 seconde pour 1 pts en vitesse.
var echelleTemps:Number = 12;
tpsTimer = ((echelleTemps-this.vitesse)*1000);
this.timer = new Timer(tpsTimer/100,100);
this.timer.addEventListener(TimerEvent.TIMER, compteur);
this.timer.addEventListener(TimerEvent.TIMER_COMPLETE, compteurFin);
/********** partie graphique ***********/
//contour de la barre de temps
this.contourTemps = new Shape();
this.contourTemps.graphics.lineStyle(1.5, 0x000000);
this.contourTemps.graphics.drawRoundRect(0,0,150,10,10);
this.contourTemps.x = 0;
this.contourTemps.y = 35;
this.conteneurStats.addChild(this.contourTemps);
//fondTemps
this.fondTemps = new Shape;
this.fondTemps.graphics.beginFill(0x000000);
this.fondTemps.graphics.drawRoundRect(0,0,148,8,10);
this.fondTemps.graphics.endFill();
this.fondTemps.x = 1;
this.fondTemps.y = 36;
this.fondTemps.alpha = 0.5;
this.conteneurStats.addChild(this.fondTemps);
//barre de temps
this.barreTemps = new Shape();
this.barreTemps.graphics.drawRoundRect(0,0,148,8,10);
this.barreTemps.x = 1;
this.barreTemps.y = 36;
this.conteneurStats.addChild(this.barreTemps);
}
private function compteur(pEvt:TimerEvent):void
{
var ratio:Number;
ratio = pEvt.currentTarget.currentCount / 100;
this.barreTemps.graphics.clear();
this.barreTemps.graphics.beginFill(0xFFFFFF);
this.barreTemps.graphics.drawRoundRect(0,0,ratio*148,8,10);
this.barreTemps.graphics.endFill();
}
private function compteurFin(pEvt:TimerEvent):void
{
this.timer.stop();
this.peutAttaquer = true;
dispatchEvent(new Event(Personnage.PEUT_ATTAQUER));
} |
Partager