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

2020/3/12

How do I make an object stay on top of another object or a platform?

CieloMungcal CieloMungcal

2020/3/12

#
i'm trying to make a game where the player can jump from an object to another, but as I run the game, the player does not stay on top of the other object. How do i fix this? I need a simple code since I'm a beginner and this game is for a school project.
danpost danpost

2020/3/12

#
Not really simple, but about as simple as can be Jump and Run Demo w/Moving Platform
CieloMungcal CieloMungcal

2020/3/13

#
how can i make my player face left whenever I make it go left? and face the other side when i want it to go right?
danpost danpost

2020/3/13

#
CieloMungcal wrote...
how can i make my player face left whenever I make it go left? and face the other side when i want it to go right?
That is included in some of the comment lines in linked demo.
CieloMungcal CieloMungcal

2020/3/13

#
how do I put a healthier on top of a player?
CieloMungcal CieloMungcal

2020/3/13

#
healthbar*
Carbon_Raven Carbon_Raven

2020/3/13

#
Maybe by moving an actor class, with a healthbar image, that moves connected to a certain players movement? That would be my approach...
danpost danpost

2020/3/13

#
CieloMungcal wrote...
how do I put a healthier on top of a player?
Please refer to my Value Display Tutorial scenario. The following path is specific to your needs: USING A BASIC ACTOR OBJECT > A BASIC CODING SYSTEM > SAMPLE CODING OF BASIC DISPLAY ACTOR IN ACTOR CLASS The only thing lacking is to put the following line at the end of the act method (adjust last value as needed):
1
valueDisplay.setLocation(getX(), getY()-60);
CieloMungcal CieloMungcal

2020/3/14

#
i'm trying to make a health bar using this code but theres an error and i don't know how to fix it public class HealthBar2 extends player2 { private int health = 100; // Say, they start with 100 health public HealthBar2() { } protected void addedToWorld(World myworld) { updateHealthBar2(0); } public int updateHealthBar2(int healthChange) { health = health - healthChange; // Note: you can add health by passing in a negative change if( health <= 0 ) { return 0; // Let's caller know we died } else if( health > 100 ) { health = 100; // can't have more than the max health } // Redraw health bar to match current health GreenfootImage myimage = new healthbar(health, 20); myimage.setColor(Color.RED); myimage.fill(); setImage(myimage); setLocation(getImage().getWidth()/2 + 40, getY()); return health; } }
Blazer Blazer

2020/3/14

#
There are different types of errors, Greenfoot lets you know which error it came upon. It will also give you a link to show which line caused the error. I believe the link is in a red color
danpost danpost

2020/3/14

#
The following line looks suspicious:
1
GreenfootImage myImage = new healthbar(health, 20);
What codes do you have for the healthbar class? (??? does it extend the GreenfootImage class ???)
CieloMungcal CieloMungcal

2020/3/14

#
don't really know what GreenfootImage is its extended to the actor
danpost danpost

2020/3/14

#
CieloMungcal wrote...
don't really know what GreenfootImage is its extended to the actor
Well, you cannot assign an actor to a variable that is declared to hold (or refer to) an image. An image (or GreenfootImage) is basically a rectangular array of Color objects. That, my dear sir, is not what an actor is (except visually, through the setting of its image).
Blazer Blazer

2020/3/15

#
GreenfootImage is not an actor, unless your healthbar class extends GreenfootImage, it will not work Try using this:
1
2
healthbar hBar = new healthbar(health, 20);
GreenfootImage myimage = hBar.getImage();
You need to login to post a reply.