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

2018/4/26

Questions Related to Setting the Background

RandomLittleWeeb RandomLittleWeeb

2018/4/26

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

/**
 * Write a description of class Player here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Player extends Actor
{
    /**
     * Act - do whatever the Player wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() {
        getWorld().setBackground(new GreenfootImage("bg.png"));
        getWorld().setBackground("bg");
        moveAround();
        move(1);
        lookForGoal();
    }
    public void moveAround() 
    {
        int Ycord = getY();
        if (Greenfoot.isKeyDown("up") == true) {
            setRotation(0);
            Ycord = getY() -10;
        }
        if (Greenfoot.isKeyDown("down") == true) {
            setRotation(180);
            Ycord = getY() + 10;
        }
        if (Greenfoot.isKeyDown("left") == true) {
            setRotation(270);
        }
        if (Greenfoot.isKeyDown("right") == true) {
            setRotation(90);
        }
    }
    public void lookForGoal() {
        if (isTouching(Goal.class) == true) {
            removeTouching(Goal.class);
        }
    }
}
Can You help me. I did code for setting the background and called the act function but my homescreen is still flank.
danpost danpost

2018/4/27

#
Remove line 17, for one thing. You may want to override the addedToWorld(World) method and move line 16 into it.
You need to login to post a reply.