This site requires JavaScript, please enable it in your browser!
Greenfoot back
GeomDshai
GeomDshai wrote ...

2016/10/16

How can i put counter lives of my character?

GeomDshai GeomDshai

2016/10/16

#
i'm trying to put a lives of my character in the game i created. and this is my code. private void live() { lives = 3; lives--; getWorld().showText("Lives:" + lives, 32, 50); } public void lives() { if(see(Mad.class)) { setLocation(50, 455); live(); if (lives <= 0) { Greenfoot.stop(); } } }
Super_Hippo Super_Hippo

2016/10/16

#
Remove the 'lives = 3' line and place the following at the beginning of the class:
1
private int lives = 3;
You also need an act method to call the lives method.
You need to login to post a reply.