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

2015/7/14

Need help with Asteroid game

sllewis sllewis

2015/7/14

#
Hi everyone, im getting an error in my Explosion class that says cannot find symbol-variable NUMBER_IMAGES. Can anyone help me figure this out? I don't know what I am doing wrong. I am a beginner at this and quite honestly, I really need a tutor on this class but if someone could help me understand what I am doing wrong and what I can do to fix it, that would be more than appreciated. Thank you in advance for your time. Here is what I have in the explosion class: import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) /** * Saysha * */ public class Explosion extends Actor { /** How many images should be used in the animation of the explostion */ private final static int IMAGE_COUNT= 12; /** * The images in the explosion. This is static so the images are not * recreated for every object (improves performance significantly). */ private static GreenfootImage images; /** Current size of the explosion */ private int imageNo = 0; /** How much do we increment the index in the explosion animation. */ private int increment=1; /** * Create a new explosion. */ public Explosion() { initializeImages(); setImage(images); Greenfoot.playSound("MetalExplosion.wav"); } /** * Create the images for explosion. */ public synchronized static void initializeImages() { if(images == null) { GreenfootImage baseImage = new GreenfootImage("explosion-big.png"); images = new GreenfootImage; for (int i = 0; i < IMAGE_COUNT; i++) { int size = (i+1) * ( baseImage.getWidth() / IMAGE_COUNT ); images = new GreenfootImage(baseImage); images.scale(size, size); } } } /** * Explode! */ public void act() { setImage(images); imageNo += increment; if(imageNo >= IMAGE_COUNT) { increment = -increment; imageNo += increment; } if(imageNo < 0) { getWorld().removeObject(this); } } }
danpost danpost

2015/7/14

#
I do not see NUMBER_IMAGES anywhere in the code; therefore I cannot see how you would get that error message.
sllewis sllewis

2015/7/14

#
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) /** * Saysha * */ public class Explosion extends Actor { /** How many images should be used in the animation of the explostion */ private final static int IMAGE_COUNT= 12; /** * The images in the explosion. This is static so the images are not * recreated for every object (improves performance significantly). */ private static GreenfootImage images; /** Current size of the explosion */ private int imageNo = 0; /** How much do we increment the index in the explosion animation. */ private int increment=1; /** * Create a new explosion. */ public Explosion() { initializeImages(); setImage(images); Greenfoot.playSound("MetalExplosion.wav"); } /** * Create the images for explosion. */ public synchronized static void initializeImages() { if(images == null) { GreenfootImage baseImage = new GreenfootImage("explosion-big.png"); images = new GreenfootImage; for (int i = 0; i < IMAGE_COUNT; i++) { int size = (i+1) * ( baseImage.getWidth() / IMAGE_COUNT ); images = new GreenfootImage(baseImage); images.scale(size, size); } } } /** * Explode! */ public void act() { setImage(images); imageNo += increment; if(imageNo >= IMAGE_COUNT) { increment = -increment; imageNo += increment; } if(imageNo < 0) { getWorld().removeObject(this); } } }
sllewis sllewis

2015/7/14

#
on my screen, it shows the NUMBER_IMAGES right after the code: if(images == null) { GreenfootImage baseImage = new GreenfootImage("explosion-big.png"); images = new GreenfootImage; <-----THIS IS WHERE IT SAYS IT, BUT WHEN I POST IT, IT DOESNT SHOW IT Why is that?
sllewis sllewis

2015/7/15

#
Okay, so I tried deleted everywhere I had images= new GreenfootImage ; and now a screen pops up and gives me this: The world constructor threw an exception, see terminal window for more details. This is what the terminal window says: java.lang.IllegalArgumentException: java.io.FileNotFoundException: Could not find file: explosion-big.png at greenfoot.GreenfootImage.loadFile(GreenfootImage.java:279) at greenfoot.GreenfootImage.<init>(GreenfootImage.java:108) at Explosion.initializeImages(Explosion.java:40) at Space.<init>(Space.java:32) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:408) at greenfoot.core.Simulation.newInstance(Simulation.java:607) at greenfoot.platforms.ide.WorldHandlerDelegateIDE$4.run(WorldHandlerDelegateIDE.java:441) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:494) at greenfoot.core.Simulation.maybePause(Simulation.java:299) at greenfoot.core.Simulation.runContent(Simulation.java:212) at greenfoot.core.Simulation.run(Simulation.java:205) Caused by: java.io.FileNotFoundException: Could not find file: explosion-big.png at greenfoot.util.GreenfootUtil.getURL(GreenfootUtil.java:539) at greenfoot.GreenfootImage.loadFile(GreenfootImage.java:276) ... 13 more java.lang.IllegalArgumentException: java.io.FileNotFoundException: Could not find file: explosion-big.png at greenfoot.GreenfootImage.loadFile(GreenfootImage.java:279) at greenfoot.GreenfootImage.<init>(GreenfootImage.java:108) at Explosion.initializeImages(Explosion.java:40) at Space.<init>(Space.java:32) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:408) at greenfoot.core.Simulation.newInstance(Simulation.java:607) at greenfoot.platforms.ide.WorldHandlerDelegateIDE$4.run(WorldHandlerDelegateIDE.java:441) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:494) at greenfoot.core.Simulation.maybePause(Simulation.java:299) at greenfoot.core.Simulation.runContent(Simulation.java:212) at greenfoot.core.Simulation.run(Simulation.java:205) Caused by: java.io.FileNotFoundException: Could not find file: explosion-big.png at greenfoot.util.GreenfootUtil.getURL(GreenfootUtil.java:539) at greenfoot.GreenfootImage.loadFile(GreenfootImage.java:276) ... 13 more java.lang.IllegalArgumentException: java.io.FileNotFoundException: Could not find file: explosion-big.png at greenfoot.GreenfootImage.loadFile(GreenfootImage.java:279) at greenfoot.GreenfootImage.<init>(GreenfootImage.java:108) at Explosion.initializeImages(Explosion.java:40) at Space.<init>(Space.java:32) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:408) at greenfoot.core.Simulation.newInstance(Simulation.java:607) at greenfoot.platforms.ide.WorldHandlerDelegateIDE$4.run(WorldHandlerDelegateIDE.java:441) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:494) at greenfoot.core.Simulation.maybePause(Simulation.java:299) at greenfoot.core.Simulation.runContent(Simulation.java:212) at greenfoot.core.Simulation.run(Simulation.java:205) Caused by: java.io.FileNotFoundException: Could not find file: explosion-big.png at greenfoot.util.GreenfootUtil.getURL(GreenfootUtil.java:539) at greenfoot.GreenfootImage.loadFile(GreenfootImage.java:276) ... 13 more java.lang.IllegalArgumentException: java.io.FileNotFoundException: Could not find file: explosion-big.png at greenfoot.GreenfootImage.loadFile(GreenfootImage.java:279) at greenfoot.GreenfootImage.<init>(GreenfootImage.java:108) at Explosion.initializeImages(Explosion.java:40) at Space.<init>(Space.java:32) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:408) at greenfoot.core.Simulation.newInstance(Simulation.java:607) at greenfoot.platforms.ide.WorldHandlerDelegateIDE$4.run(WorldHandlerDelegateIDE.java:441) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:494) at greenfoot.core.Simulation.maybePause(Simulation.java:299) at greenfoot.core.Simulation.runContent(Simulation.java:212) at greenfoot.core.Simulation.run(Simulation.java:205) Caused by: java.io.FileNotFoundException: Could not find file: explosion-big.png at greenfoot.util.GreenfootUtil.getURL(GreenfootUtil.java:539) at greenfoot.GreenfootImage.loadFile(GreenfootImage.java:276) ... 13 more Can anyone help me with this? I am so confused. Just a non-tradition student trying to get a degree for once and I don't want to fail. Please help me?
danpost danpost

2015/7/15

#
As far as the 'NUMBER_IMAGES' variable, you probably meant to use 'IMAGE_COUNT'. As far as the 'Could not find file' error, make sure that you have the name of the file correct -- case must match for all characters of both the name and the suffix of the filename.
You need to login to post a reply.