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

2020/4/19

Scrolling

AdiBak AdiBak

2020/4/19

#
Hello, I'm trying to make an Agario clone. I have the player who follows the mouse. But I am stuck on how to make the food 'scroll' in the screen as the player moves. Can someone please help? Thank you. My code for Player class:
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() 
    {
        if (Greenfoot.mouseMoved(null)){
            MouseInfo e = Greenfoot.getMouseInfo();
            if (e != null){
                turnTowards(e.getX(), e.getY());
                move(3);
            }
           
        }
        // Add your action code here.
    }    
}
My code for Food class:
public class Food extends Actor
{
    public Food(){
        getImage().scale(30, 30);
    }
    /**
     * Act - do whatever the Food wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
        if (Greenfoot.mouseMoved(null)){
            MouseInfo e = Greenfoot.getMouseInfo();
            if (e != null){
                //turnTowards(e.getX(), e.getY());
                move(-3);
            }
           
        }
    }    
}
danpost danpost

2020/4/19

#
Please refer to my Scrolling Tutorial scenario.
You need to login to post a reply.