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
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);
}
}
