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

2024/5/2

getting actor height from world class

NewUser567 NewUser567

2024/5/2

#
I want to use a for loop to insert a horizontal line of rocks as a border. How can i do this from the world class? I would need to get the actor’s width and height from the world class right? They have to all be at the same height, and right next to each other
danpost danpost

2024/5/2

#
NewUser567 wrote...
I want to use a for loop to insert a horizontal line of rocks as a border. How can i do this from the world class? I would need to get the actor’s width and height from the world class right? They have to all be at the same height, and right next to each other
Yes. You can get the dimensions of a rock before the loop:
Actor rock = new Rock();
int wRock = rock.getWidth();
int hRock = rock getHeight();
int y = this.getHeight()-hRock/2;
for (int x=wRock/2; x<this.getWidth(); x+=wRock) {
    addObject(new Rock(), x, y);
}
This should put them along the bottom of the screen as a border.
You need to login to post a reply.