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

2021/2/23

Position Same images in different positions

Jemy Jemy

2021/2/23

#
Please how can i position same image in different static positions on the world. that is, each time, i start the program, these images are at the same positions. Thanks
danpost danpost

2021/2/23

#
Jemy wrote...
Please how can i position same image in different static positions on the world. that is, each time, i start the program, these images are at the same positions. Thanks
In world constructor, have image drawn onto background image. Attempt and show attempted code if more assistance is required.
Jemy Jemy

2021/2/23

#
public void populate() { addObject(new Person(), (ROW_HEIGHT*3)/5, COLUMN_HEIGHT/6); addObject(new Person(), ROW_HEIGHT-620, (COLUMN_HEIGHT/(5/2))); addObject(new Person(), (ROW_HEIGHT-120), (COLUMN_HEIGHT/(5/2))); addObject(new Person(), ROW_HEIGHT-520, COLUMN_HEIGHT-60); addObject(new Person(), ROW_HEIGHT-200, COLUMN_HEIGHT-60); } I want to create five person at specific positions on the world and compare their random number to determine the person with lowest random value between 0 and 301. The above code is what i have done. i have tried to use for loop but my challenge is placing them at specific positions
danpost danpost

2021/2/23

#
It is possible to use a for loop, but that would require the location coordinates be placed in an array. What you show would have them placed at the same locations every time. What code do you have in Person class? (I presume the random numbers are given there)
Jemy Jemy

2021/2/23

#
Thank you, I have implemented it using for loop i had to hard code the location as an array. public void populate() { for(int i=0; i<5;i++){ int x={600,380,880,480,800}; int y={100,300,300,540,540}; addObject(new Server(), x, y); } } how do i compare their random number to determine the lowest. any idea pleas
danpost danpost

2021/2/23

#
danpost wrote...
What code do you have in Person class? (I presume the random numbers are given there)
I guess it is called Server class now.
Jemy Jemy

2021/2/23

#
danpost wrote...
danpost wrote...
What code do you have in Person class? (I presume the random numbers are given there)
I guess it is called Server class now.
yes
You need to login to post a reply.