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

2014/10/23

Image isn't appearing...

BryanGSMST BryanGSMST

2014/10/23

#
When I make a new ProtonWave, I hear the noise, but I never see it.
import greenfoot.*;  // (World, Actor, GreenfootImage, and Greenfoot)

/**
 * A proton wave that expands and destroys things in its path.
 * 
 * @author Michael Kolling
 * @version 0.1
 */
public class ProtonWave extends Actor
{
    /** The damage this wave will deal */
    private static final int DAMAGE = 30;
    
    /** How many images should be used in the animation of the wave */
    private static final int NUMBER_IMAGES= 30;
    
    /** 
     * The images of the wave. This is static so the images are not
     * recreated for every object (improves performance significantly).
     */
    private static GreenfootImage[] images;
    private int imageCount = 0;
    /**
     * Create a new proton wave.
     */
    public ProtonWave() 
    {
        initializeImages();
        setImage(images[0]);
        Greenfoot.playSound("proton.wav");
    }
    /** 
     * Create the images for expanding the wave.
     */
    public static void initializeImages() 
    {
        if(images == null) 
        {
            GreenfootImage baseImage = new GreenfootImage("wave.png");
            images = new GreenfootImage[NUMBER_IMAGES];
            int i = 0;
            while (i < NUMBER_IMAGES) 
            {
                int size = (i+1) * ( baseImage.getWidth() / NUMBER_IMAGES );
                images[i] = new GreenfootImage(baseImage);
                images[i].scale(size, size);
                i++;
            }
        }
    }
    
    public void grow()
    {
        if (imageCount >= NUMBER_IMAGES)
        {
            getWorld().removeObject(this);
        }
        else {
            setImage(images[imageCount]);
            imageCount++;
        }
    }
    
    /**
     * Act for the proton wave is: grow and check whether we hit anything.
     */
    public void act()
    { 
        grow();
    }
    
}
Alwin_Gerrits Alwin_Gerrits

2014/10/23

#
I think you should post your code which determines where to place the image in your world as well. Because for as far as I can see there doesn't seem to be large problems with your code, but if you're not placing it in your world it's obviously not going to appear. So maybe place the code where you use something like addObject(new PortonWave); or whatever you used to place it in your world. It can be I can't help much even if you post it, but the people with more experience can at least help you faster if you post that part of the code right now.
Super_Hippo Super_Hippo

2014/10/24

#
I would suggest to comment out line 37 because I don't think that an array can be 'null'.
You need to login to post a reply.