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

2012/1/20

Score not going up

Blight Blight

2012/1/20

#
Hi, I'm creating a game where the user can get lives. But the counter is not going up when the user gets a new life? The counter does go down when he dies. Here is my code: if(gethitsbyenemy()) { Lives--; myLabel.setText("Lives: " + Lives); setLocation(125, 292); } This one is working. This one is not: if(checkForNewLife()) { Lives++; myLabel.setText("Lives: " + Lives); } Anyone knows the answer? Thanks in advance.
kiarocks kiarocks

2012/1/20

#
what is checkForNewLife? (code?)
Blight Blight

2012/1/20

#
public boolean checkForNewLife() { Actor Coin = getOneObjectAtOffset(0, 0, Coin.class); if(Coin != null) { return true; } else { return false; } }
kiarocks kiarocks

2012/1/20

#
how is it not working?
Blight Blight

2012/1/20

#
The score never changes on the screen, it keeps displaying Lives: 3. (The int Lives starts with 3)
Builderboy2005 Builderboy2005

2012/1/20

#
getOneObjectAtOffset() will only work if both of you are on the exact same spot. Do you know for sure if this is happening? Would you perhaps want getOneIntersectingObject() instead?
Blight Blight

2012/1/20

#
Tried it, still not working.
kiarocks kiarocks

2012/1/20

#
Have you tried
public boolean checkForNewLife()
{
Actor Coin = getOneIntersectingObject(Coin.class);
if(Coin != null) return true;
return false;
}
You need to login to post a reply.