actionscript 3 - How to make angry birds scoring type "three stars rating" in flash? -


i want make scoring system shows star based on points angry birds.

if get: 3 points = 3 stars, 1-2 points = 2 stars, 0 = 1 star

the stars image. points save after answering of 3 questions. points appear in form of star above. desperately need this.

  • create image 1 "lit" star, , 1 one "dim" star;
  • place instances of them on stage, "lit" stars overlapping "dim" stars, being hidden initially;
  • keep array references "lit" instance images, , turn visible number, proportional score.

below more of general solution:

public class starsscoring extends sprite {      [embed(source = "path/to/dimimage.jpg")]     private var _dimstar: class;      [embed(source = "path/to/litimage.jpg")]     private var _litstar: class;      private const gap: uint = 10;     private const group_x: uint = 25;     private const group_y: uint = 25;      private var _litstars: array = [];     private var _numstars: uint;      private function _buildscoringui(): void {         var litstar: bitmap, dimstar: bitmap, hoffset: number = group_x;         (var i: int = 0; < _numstars; i++) {             litstar = (new _litstar()) bitmap;             dimstar = (new _dimstar()) bitmap;              litstar.x = dimstar.x = hoffset;             litstar.y = dimstar.y = group_y;             litstar.visible = false;             addchild(_dimstar);             addchild(_litstar);              _litstars.push(litstar);              hoffset += (litstar.bitmapdata.width + gap);         }     }      public function starsscoring(numstars: uint = 3): void {         _numstars = numstars;         _buildscoringui();     }      public function updatescore(score: uint, total: uint): void {         var percent: number = (score / total);         var threshold: uint = math.round(percent * _litstars.length);         (var i: int = 0; < _litstars.length; i++) {             var litstar: bitmap = (_litstars[i] bitmap);             litstar.visible = (i <= threshold);         }     } } 

the advantage class, can use number of stars want, , scoring adapt automatically. use it:

var stars : starsscoring = new starsscoring (3); addchild (stars); stars.updatescore (1,3); // "lit" first star image 

never tested / compiled code (will when have chance), so, should point in right direction.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -