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

mik's Comments

Back to mik's profile

Okay, we figured out what the problem is that causes the lag in the game. It is capitalisation of image files. Some of your classes have images names assigned with capitals (e.g. "A.gif") while your image file name on disk uses lowercase ("a.gif"). Sometimes the problem is in the suffix ("smaller.GIF" vs "smaller.gif"). Maybe this happened because you changed the names of the image files after they were set as class images for a class. The Windows file system is case-insensitive, so there it all works. But Java, when reading from jar files (which happens when running in a browser) is case sensitive, so it causes various problems. The fix: Right-click on every one of your classes, select 'Set image', and assign the class image again. This should fix the mis-spelling of the stored class images. Then export again and -- fingers crossed -- it should all work. Michael
mikmik

2008/10/11

That explains the tomatoes - finally! Great game. (And, no, applets -that is Java programs running in a web browser- are not allowed to write files. That's a security feature against malicious code.) Good job, Michael
You're right - the lag is still there. That's strange. When I tried modifying your code, it was also still there at first, but then I exported again, and then it was gone. It was perfectly fine. I am not quite sure why that is right now, but I'll look into it and will try to find out. Your code look fine -- maybe it is a very subtle Greenfoot problem.
Hi kamegani! This is really great work. The problem with the lagging can be fixed. It comes from repeatedly loading images from files, which you should try to avoid. In your 'Letter' class, instead of assigning the images from the file for every new letter, like this image = new GreenfootImage(name+".gif"); try loading the image files only once, and then re-using them. For example, define a static array for all 26 images: private static final GreenfootImage[] images; Then use a static initializer block to load the images: static { images = new GreenfootImage[26]; for (int i=0; i<26; i++) { String name = new String(""+alphabet[i]); name = name.toLowerCase(); images[i] = new GreenfootImage(name+".gif"); } } A static initialiser block is a little unusual: You write it exactly as above before the constructor. It really has no method header. It will be executed exactly once when the class is loaded. You will then have an array with all the letter images. In your constructor, you can then write image = images[i]; thus reusing the images, without loading them from file every time. Another few tips: - for the special items, such as the LargerCatcherItem, which never change the image at all, you do not need to set the images programmatically.In other words: you can get rid of the two lines image = new GreenfootImage("larger.gif"); this.setImage(image); If the class has that image assigned, the objects will just use the class image by default. - Your scenario is slow to load because it is very big. You have two files in your image folder and subfolder which you can delete, named 'thumbs.db'. These may come from your graphics program, or Windows, and they are very big and not needed. - You also have some very large image files. Some images are over 100k, 200k, or even 300k big. You should scale them down before including them, rather than scaling them inside your program. That will save some time up- and downloading your game. Nice work, though. I played it without the lag now, and I like it! Michael
Cool. Really nice to play with this. I case people haven't noticed: when the scenario is paused, you can drag the trees around and make your own layout, to make it a little more difficult for the birds, or to chase them around a particular path...
mikmik

2008/9/22

A fanfare and applause! Who could ask for more...
mikmik

2008/9/22

I just spent ten minutes solving it (and I did!), and when I was done it just stopped... I had expected at least a fanfare, some flashing lights, and maybe some fireworks for my efforts! Where's my reward?
I am currently using Java 5. Greenfoot is usually careful to compile everything to Java 5 format class files (even if you develop with Java 6). Dies the project contain classes compiled outside of Greenfoot? If so, you should set a flag on compilation to compile to Java 5 format.
I added the source for it now.