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

2021/12/21

help setting background in my world

roonie01 roonie01

2021/12/21

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class MyWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MyWorld extends World
{
    int x;
    int y;
    GreenfootImage background;
    /**
     * Constructor for objects of class MyWorld.
     * 
     */
    public MyWorld()
    {    
        // Create a new world with 1600x1200 cells with a cell size of 1x1 pixels.
        super(1600, 1200, 1); 
         
        x = getWidth()/2; 
        y = getHeight()/2;
        
        
        //adds the image for the background
        background = new GreenfootImage("space.png");
        //sets the image
        setImage(background);
        // makes a new instance for rocket
        addObject(new Rocket(),getWidth()/2,getHeight()/2); 
        
        
        

        
    }

    
}
roonie01 roonie01

2021/12/21

#
new code is here also need help with adding multiple enemys along the top of my screen
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class MyWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MyWorld extends World
{
    int x;
    int y;
    GreenfootImage background;
    /**
     * Constructor for objects of class MyWorld.
     * 
     */
    public MyWorld()
    {    
        // Create a new world with 1600x1200 cells with a cell size of 1x1 pixels.
        super(1600, 1200, 1); 

        x = getWidth()/2; 
        y = getHeight()/2;

        //adds the image for the background
        background = new GreenfootImage("space.png");
        //sets the image
        //this.setImage(background);
        // makes a new instance for rocket
        addObject(new Rocket(),getWidth()/2,getHeight()/2); 

        addEnemy();
        
    }

    public void addEnemy()
    {
        int x1 = 1600 / 8;
        for(int i =0;i<=1600;i=i+x1)
        {
            
            addObject( new enemy1(),200+x1,30);
        }
    }
}

You need to login to post a reply.