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

2021/4/23

How to use getImage in World class?

Jeeshan Jeeshan

2021/4/23

#
Is it possible to use getImage in world class? I have a code in actor class and I want to move it to the world class. However getImage doesn't work in the world class. Is there any code similar to getImage that I can use in World class?
Jeeshan Jeeshan

2021/4/23

#
This is the code that I want to transfer to World class }
Jeeshan Jeeshan

2021/4/23

#
public class Background1 extends Actor
{
    public void act() 
    {
        super.act();
    }  
    public void scroll()
    {
        if(getY()>getImage().getHeight()*1.5)
        {
            setLocation(getX(),getWorld().getHeight()-895);
        }
        setLocation(getX(),getY()+5);
    }
}
Super_Hippo Super_Hippo

2021/4/24

#
For some reason it is called “getBackground” in the World class.
danpost danpost

2021/4/25

#
Super_Hippo wrote...
For some reason it is called “getBackground” in the World class.
I have a feeling that naming was intentional, as the background image is not supposed to contain any transparency. In fact, if you look at the images supplied by greenfoot, all background images are jpg (or jpeg) images any all actor images are of png type.
Jeeshan Jeeshan

2021/4/25

#
Thank for all the help. I have overcome that code and am now unfortunately stuck in another part
You need to login to post a reply.