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

2019/1/11

Moving Scenery Troubles

The_Beast0007 The_Beast0007

2019/1/11

#
This game is only a prototype. I am creating a top-down open-world game and I have a plan to make the scenery move whilst the character turns and animates (but doesn't move) . The problem is after a few seconds of the scenery moving in any direction it freezes and won't move any more. Here's my code:
import greenfoot.*;

public class Scenery extends Actor
{
    private int step = 5;
    public void Move() 
    {
        int y = getY();
        int x = getX();
        if(Greenfoot.isKeyDown("w")) y += step;  
        if(Greenfoot.isKeyDown("s")) y -= step;
        if(Greenfoot.isKeyDown("a")) x += step;  
        if(Greenfoot.isKeyDown("d")) x -= step;
        setLocation(x, y);
        
    }
    public Scenery(int width, int height) {
        GreenfootImage image = getImage();
        image.scale(width, height);
        setImage(image);
    }
    public void act() 
    {
        Move();
    }    
}
Here's a video showing the problem: This is it
danpost danpost

2019/1/11

#
The_Beast0007 wrote...
This game is only a prototype. I am creating a top-down open-world game and I have a plan to make the scenery move whilst the character turns and animates (but doesn't move) . The problem is after a few seconds of the scenery moving in any direction it freezes and won't move any more. << Code Omitted >> << Video Link Omitted >>
You probably are in a bounded world and the Scenery actor is prevented from being located (using its center point) beyond the edges of the world. You could unbound the world (see documentation on World class constructors), but then you will need to restrict the actor to ensure it covers the world window. You can test it out to see what I mean. The image of your scenery does appear to have a regular pattern; so you could shift it when needed to maintain the actor in the window while still giving the appearance of continuous movement in any direction.
The_Beast0007 The_Beast0007

2019/1/11

#
YAY! It worked, thank you so much danpost. I had no idea about the bounded option for worlds!
You need to login to post a reply.