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

2013/12/2

World doesn't create

Mellow Mellow

2013/12/2

#
Can anybody explain why this doesn't work?
public haven()
    {    
        // Create a new world with 401x400 cells with a cell size of 1x1 pixels.
        super(401, 400, 1); 
       
      
       
       for(int y = 0; y <= 400; y++){
           for(int x = 0;x <= 401; x++){
               if(y <= 100){
                  addObject(new Water(), x, y);
                  
                }
                else if(y > 100 && y <= 250){
                  addObject(new Dijk(), x, y);
                  
                }
                else if(y > 250 && y <= 400){
                  addObject(new Binnendijk(), x, y);
                  
                }
            }
        }
    
}
It doesn't give any errors, it just doesn't end up doing anything.
davmac davmac

2013/12/2

#
I think you'll find it does do something, it's just that it takes quite a long time to do it. You have a loop inside a loop, so a total of 400 x 400 iterations. That's not too many, but adding an object to the world isn't particularly fast when you run your scenario in the Greenfoot IDE (it will run much faster if you export it to this website, or to a standalone jar file).
You need to login to post a reply.