Copy link to clipboard
Copied
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?
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
Copy link to clipboard
Copied
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
Find more inspiration, events, and resources on the new Adobe Community
Explore Now