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:
Here's a video showing the problem: This is it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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(); } } |