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

2020/3/21

Images not showing

ezio4864 ezio4864

2020/3/21

#
I've created actor classes to serve as texts on my game. Whenever I set their images by right clicking them and adding them into the world, they only display as the greenfoot icons. The images are in the images folder and are in .png format. I also tried setting the images through code using these lines:
import greenfoot.*;
public class controls extends Actor
{
    public void act() 
    {
        setImage("instruc.png");
    }    
}
but the following error shows:
java.lang.IllegalArgumentException: Could not load image from: instruc.png at greenfoot.GreenfootImage.loadURL(GreenfootImage.java:277) at greenfoot.GreenfootImage.loadFile(GreenfootImage.java:302) at greenfoot.GreenfootImage.<init>(GreenfootImage.java:108) at greenfoot.Actor.setImage(Actor.java:439) at controls.act(controls.java:18) at greenfoot.core.Simulation.actActor(Simulation.java:567) at greenfoot.core.Simulation.runOneLoop(Simulation.java:530) at greenfoot.core.Simulation.runContent(Simulation.java:193) at greenfoot.core.Simulation.run(Simulation.java:183)
danpost danpost

2020/3/21

#
Change "void act" to "controls". I doubt this will fix the error, however
ezio4864 ezio4864

2020/3/21

#
Yes, I tried this as well, no luck so far. edit: This error shows
java.lang.IllegalArgumentException: Could not load image from: instruc.png at greenfoot.GreenfootImage.loadURL(GreenfootImage.java:277) at greenfoot.GreenfootImage.loadFile(GreenfootImage.java:302) at greenfoot.GreenfootImage.<init>(GreenfootImage.java:108) at greenfoot.Actor.setImage(Actor.java:439) at controls.<init>(controls.java:6) at instruc.prepare(instruc.java:34) at instruc.<init>(instruc.java:20) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) at bluej.runtime.ExecServer$3.lambda$run$1(ExecServer.java:834) at bluej.runtime.ExecServer.lambda$runOnTargetThread$1(ExecServer.java:939) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:470) at greenfoot.core.Simulation.maybePause(Simulation.java:299) at greenfoot.core.Simulation.runContent(Simulation.java:190) at greenfoot.core.Simulation.run(Simulation.java:183)
ezio4864 ezio4864

2020/3/21

#
I increased the size of the image and it worked. Perhaps the image size was too small? Anyway, thank you for your time!
You need to login to post a reply.