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

2013/5/12

what does this mean and how to sovle it?

Avik Avik

2013/5/12

#
It says: “Error when instantiating world.” “It was not possible to instantiate a new world. The reason for this usually that that the world does not have a public default constructor (a constructor that takes no parameters) or that the world is not a public class. please help me!
Gevater_Tod4711 Gevater_Tod4711

2013/5/12

#
This error means that the world couldn't be initialised because of an error in the world. If you post the code of the world we can tell you whats wrong with it.
Avik Avik

2013/5/12

#
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) /** * A class that has a scrolling background image * * @author avik */ public class ScrollWorld extends World { private static final GreenfootImage bgImage = new GreenfootImage("balloon.png"); private static final int scrollSpeed = 1; private GreenfootImage scrollingImage; private int scrollPosition = 0; ScrollWorld() { super(800, 400, 1); GreenfootImage background = new GreenfootImage(800, 400); scrollingImage = getScrollingImage(800, 400); background.drawImage(scrollingImage, 0, 0); setBackground(background); addObject(new balloon(), 350, 200); } public void act() { if(scrollSpeed > 0 && scrollPosition <= 0) { scrollPosition = getWidth(); } if(scrollSpeed < 0 && scrollPosition >= getWidth()) { scrollPosition = 0; } scrollPosition -= scrollSpeed; paint(scrollPosition); } /** * Paint scrolling image at given position and make sure the rest of * the background is also painted with the same image. */ private void paint(int position) { GreenfootImage bg = getBackground(); bg.drawImage(scrollingImage, position, 0); bg.drawImage(scrollingImage, position - scrollingImage.getWidth(), 0); } /** * Returns an image with the given dimensions. */ private GreenfootImage getScrollingImage(int width, int height) { GreenfootImage image = new GreenfootImage(width, height); for(int x = 0; x < width; x += bgImage.getWidth()) { for(int y = 0; y < height; y += bgImage.getHeight()) { image.drawImage(bgImage, x, y); } } return image; } }
danpost danpost

2013/5/12

#
Change line 16 from 'ScrollWorld()' to 'public ScrollWorld()'.
Avik Avik

2013/5/12

#
thank you very much
You need to login to post a reply.