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

2022/2/7

Moving World

PetrusderEchte PetrusderEchte

2022/2/7

#
Hello, i have this problem: My game has a big world. The image goes to the right and left. But when i place my testperson und you walk in one direction, he moves out the image. So my question is, is it possible that the world moves with the charakter? And how to do this. These are my codes (test world):
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)


public class SpielWelt extends World
{
    private static int zellenGroesse = 70;

    /**
     * Erschaffe eine Welt mit 14 * 10 Zellen.
     */
    public SpielWelt()
    {
        super(50, 6, zellenGroesse);
        setBackground("images/istockphoto-1200036161-612x612.jpg");
     
        Greenfoot.setSpeed(15); 
       

     
    }
}      


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

/**
 * Write a description of class Mann here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class test extends Actor
{
   
    public void act() 
    {
       
    { 
       int speed = 1;
       if (Greenfoot.isKeyDown("up"))
       setLocation(getX(), getY() - speed) ;
       if (Greenfoot.isKeyDown("down"))
       setLocation(getX(), getY() + speed) ;
       if (Greenfoot.isKeyDown("left"))
       setLocation(getX() - speed, getY());
       if (Greenfoot.isKeyDown("right"))
       setLocation(getX() + speed, getY());
       
      
    }    
} 
}
Thanks for any help!
danpost danpost

2022/2/7

#
PetrusderEchte wrote...
My game has a big world. The image goes to the right and left. But when i place my testperson und you walk in one direction, he moves out the image. So my question is, is it possible that the world moves with the charakter?
Please refer to my Scrolling Tutorial scenario, which refers to a class that is demonstrated in my Scroller Class Demos scenario.
You need to login to post a reply.