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

2015/10/27

Help with creating object in a for-string

Skayo Skayo

2015/10/27

#
i want to create more than one object in a for-string, should be like this: }
randstreifen = new Randstreifen();
        for(int i = 0; i < 5; i++){
            addObject(randstreifen, 300, getY() + 30);
        }
it says cannot find symbol - method getY(); pls help!
Super_Hippo Super_Hippo

2015/10/27

#
What do you think should 'getY' return? The code is (probably) in a world subclass. A world doesn't have a position inside a world (which 'getX' and 'getY' would return). To add more than one object, move the first line into the for-loop. If the 'Randstreifen' is only a line on the background, you could draw it on the background instead of creating objects.
You need to login to post a reply.