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

2018/1/9

I just wanna spawn one ball

Sarwa35 Sarwa35

2018/1/9

#
Hey Guys Ihave a Problem.I am want to spawn at 30 seconds another Ball but it spawns like 20 .How can i do that ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  public MyWorld() {
    super (640,400,1);
    this.addObject( new Ball3(),100,100);
     
     
}
    int Zeit = 0;
int counter = 0;
    public void act()
    {
            
            Greenfoot.delay(1);
Zeit = Zeit+1;
if ( Zeit==100){
     
Zeit = 0;
counter = counter+1;
 
}
    showText((counter)+"Zeit",30,40);
      if (counter==30.01){
    this.addObject(new Ball2(),100,100);
    }
    }
}
danpost danpost

2018/1/9

#
From what I can tell, you should only have one spawned every 1.5 to 2.0 minutes. I do not like the use of the delay in your code, but that is another thing ... so, my question is this: What codes are you using in the Ball2 and Ball3 classes?
Sarwa35 Sarwa35

2018/1/9

#
that one for both
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
   int dx =3;
   int dy =-2;
public void act()
   {
    setLocation(getX()+dx, getY()+dy);
       if (getX()>=620) {
           dx = -dx;
       }
       if (getY()<=20) {
           dy = -dy;
       }
       if (getX()<=20) {
           dx =-dx;
       }
       if (getY()>=490) {
           dy = -dy;
       }
i am making a game named Collosion
danpost danpost

2018/1/9

#
Maybe I am not understanding your issue correctly. If you want to increase the time between ball spawnings, increase the value of what Zeit or counter need to end up at.
xbLank xbLank

2018/1/10

#
danpost wrote...
Maybe I am not understanding your issue correctly. If you want to increase the time between ball spawnings, increase the value of what Zeit or counter need to end up at.
This. You are obviously missing a basic understanding of your own code which was probably caused by copying too much from other projects. I would advise you to re do it in your way so you know what you are actually doing. The problem mentioned above is the reason for most questions in this forum.
Sarwa35 Sarwa35

2018/1/10

#
I got it but thanks for trying to help me
You need to login to post a reply.