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

2020/12/29

Random number

1
2
3
danpost danpost

2021/1/4

#
mik. wrote...
Is their any other way to make a class reference(line 34) I think by doing this may overcome the lag permanently
No. It will not change lag at all.
mik. mik.

2021/1/4

#
Then it might be due to image its size(35.9 kb)???
mik. mik.

2021/1/4

#
If not then what else do u think that can be the cause of lag???
danpost danpost

2021/1/4

#
mik. wrote...
Then it might be due to image its size(35.9 kb)???
If the clock image is that large, maybe you should have it pre-loaded.
mik. mik.

2021/1/5

#
So is their any other way to make an instance of it and then add it again and again to the world??? I tried to create an instance of clock and it works properly without lag but i want it to add it again and again to world
danpost danpost

2021/1/5

#
Use Paint (application) tto scale the clock image down to 125x125. Then try your code given here without the scaling line in the Clock constructor.
mik. mik.

2021/1/6

#
I removed line 4 and 5 frm my code And now i will be able to show it to my teacher. Its no more lagging. Thanks for helping me
mik. mik.

2021/1/6

#
I got another problem java.lang.IllegalArgumentException: bound must be positive in line 8
int[] question = { 0, 1, 2 };
Integer lastDraw;
 
// to draw
 
int clocks = getWorld().getObjects(Clock.class).size();
boolean lastPos = lastDraw != null && lastDraw != 0;
int rand = Greenfoot.getRandomNumber(question.length-clocks-(lastPos ? 1 : 0));
rand += clocks;
if (rand == 0) getWorld().addObject(new Clock(), 50, 50), 
else
{
    if (lastPos && rand >= lastDraw) rand++;
    getWorld().showText(""+rand, 50, 50);
}
lastDraw = new Integer(rand);
danpost danpost

2021/1/6

#
mik. wrote...
java.lang.IllegalArgumentException: bound must be positive in line 8
You must have multiple clocks in your world at one time.
mik. mik.

2021/1/6

#
Yes. So how will i fix it???
mik. mik.

2021/1/6

#
Will i have to make it private???
danpost danpost

2021/1/6

#
mik. wrote...
Yes. So how will i fix it???
The code above should only allow one clock in the world. If you have more, than the extra are coming from somewhere else.
You need to login to post a reply.
1
2
3