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

2018/4/5

Randomly rotate objects?

Recorsi Recorsi

2018/4/5

#
Hello, I have a method for spawning "Rocks" which looks like this:
public void placeRocksBeginning()
    {
       for (int i = 0; i < 25; i++) 
       {
          int x = Greenfoot.getRandomNumber(900);
          int y = Greenfoot.getRandomNumber(900);
          addObject (new Rock(), x , y);
       }
How can i set a rotation for the rocks?
Asenoju Asenoju

2018/4/5

#
How exactly do you want to rotate them? Do you want to rotate them while they are falling or should they just have one random rotation angle?
Vercility Vercility

2018/4/5

#
Rock rock = new Rock();
rock.setRotation(90);
addObject(rock,x,y);
Recorsi Recorsi

2018/4/5

#
Asenoju wrote...
How exactly do you want to rotate them? Do you want to rotate them while they are falling or should they just have one random rotation angle?
They just should have a random rotation angle
Recorsi Recorsi

2018/4/5

#
Vercility wrote...
Rock rock = new Rock();
rock.setRotation(90);
addObject(rock,x,y);
Thanks
danpost danpost

2018/4/5

#
Recorsi wrote...
Vercility wrote...
Rock rock = new Rock();
rock.setRotation(90);
addObject(rock,x,y);
Thanks
I do not see any randomness in the rotation of the rocks.
Recorsi Recorsi

2018/4/6

#
danpost wrote...
Recorsi wrote...
Vercility wrote...
Rock rock = new Rock();
rock.setRotation(90);
addObject(rock,x,y);
Thanks
I do not see any randomness in the rotation of the rocks.
No problem, i just changed it a bit:
public void placeRocksBeginning()
    {
       for (int i = 0; i < 25; i++) 
       {
          int x = Greenfoot.getRandomNumber(900);
          int y = Greenfoot.getRandomNumber(900);
          Rock rock = new Rock();
          rock.setRotation(Greenfoot.getRandomNumber(360));
          addObject(rock,x,y);
       }
    }
You need to login to post a reply.