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

2020/1/18

method doesn't work

StudyNerd StudyNerd

2020/1/18

#
Basically, I got a code from one class where it would call another class method public void healthDecrease() { if (isTouching(Enemy.class)) { removeTouching(Enemy.class); healthDown.healthLess(); } } ^^^ this is the code for one class named Player public void healthLess() { setImage(health); healthNum++; if (healthNum == 6) { healthNum = 0; } } ^^^ this is the code for the HealthBar The problem is that somehow the healthDown.healthLess(); doesn't transfer to the method healthLess(). Anyone knows the problem?
danpost danpost

2020/1/18

#
How is healthDown declared and inittilized in the Player class and where and how is it created?
StudyNerd StudyNerd

2020/1/18

#
danpost wrote...
How is healthDown declared and inittilized in the Player class and where and how is it created?
HealthBar healthDown = new HealthBar(); it is created here public class Player1 extends Actor { int runSpeed = 5; int num = 1; int deltay = 0; int s = 1; int jumpSprite = 1; public static int level = 1; //Player facing right private GreenfootImage run1 = new GreenfootImage; //Player facing left private GreenfootImage runL1 = new GreenfootImage; //Player facing left private GreenfootImage jump1 = new GreenfootImage; Counter count = new Counter(); HealthBar healthDown = new HealthBar();
danpost danpost

2020/1/18

#
StudyNerd wrote...
it is created here << Code Omitted >>
Okay. Where is it added into the world?
StudyNerd StudyNerd

2020/1/18

#
danpost wrote...
StudyNerd wrote...
it is created here << Code Omitted >>
Okay. Where is it added into the world?
what do you mean?
danpost danpost

2020/1/18

#
StudyNerd wrote...
what do you mean?
Do you see a HealthBar object in your world? Is there no change in it -- and that is why you are saying it does not work?
StudyNerd StudyNerd

2020/1/18

#
danpost wrote...
StudyNerd wrote...
what do you mean?
Do you see a HealthBar object in your world? Is there no change in it -- and that is why you are saying it does not work?
I figured it out. Thank you for your time. You are a legend that replies to all the posts. Dan the man
You need to login to post a reply.