Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Lifesystem in as3

Guest
Jan 07, 2014 Jan 07, 2014

Hello,

I'm trying to make a game and within that game i'd like a lifesystem. The player has 3 lifes (shown as 3 hearts in the game). This is what I have so far:

var lifes:int = 3;

function checkForHits() {

if(Player.hitTestObject(Zombie)) {
Heart3.x=1100;
lifes --;
Player.x=200,Player.y=600;

}

if (lifes == 0) {

gotoAndStop("gameover");

}

It works, after 3 deaths I progress to the gameover screen. My problem is: how do I show that graphically? The first heart (called heart3) dissapears as I want it to, but I have no clue how to do the same with the second and third heart. Any suggestions?

TOPICS
ActionScript
291
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Jan 08, 2014 Jan 08, 2014

you can reference objects with this construction

var num:int = 5;

this["object"+String(num)].visible = false;

//this will make any displayObject with the instance name object5 invisible on th stage;

in your case:

if(Player.hitTestObject(Zombie)) {
this["Heart"+String(lifes)].x=1100;
lifes --;

}

this is an easy way to tie your UI to the actual gaming data

Translate
Guru ,
Jan 08, 2014 Jan 08, 2014
LATEST

you can reference objects with this construction

var num:int = 5;

this["object"+String(num)].visible = false;

//this will make any displayObject with the instance name object5 invisible on th stage;

in your case:

if(Player.hitTestObject(Zombie)) {
this["Heart"+String(lifes)].x=1100;
lifes --;

}

this is an easy way to tie your UI to the actual gaming data

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines