I made some code to make it look like my game is focused on my actor, and the background moves accordingly when I press the arrow keys. It works fine when I move down and to the right, but in the other two directions, it glitches and starts to repeat the texture a lot. I wanted to know why this happens and how to fix it, i inserted the code that I'm using
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 27 28 29 30 | public void act() { scrollBackground(); } public void scrollBackground() { GreenfootImage bg = new GreenfootImage(getBackground()); if (Greenfoot.isKeyDown( "right" )) { getBackground().drawImage(bg, - 10 , 0 ); getBackground().drawImage(bg, getWidth()- 100 , 0 ); } if (Greenfoot.isKeyDown( "left" )) { getBackground().drawImage(bg, - 10 , 0 ); getBackground().drawImage(bg, getWidth()+ 100 , 0 ); } if (Greenfoot.isKeyDown( "up" )) { getBackground().drawImage(bg, 0 , + 10 ); getBackground().drawImage(bg, 0 , getHeight()+ 100 ); } if (Greenfoot.isKeyDown( "down" )) { getBackground().drawImage(bg, 0 , - 10 ); getBackground().drawImage(bg, 0 , getHeight()- 100 ); } } |