Okay so I have a fully working scrolling world, when my actor reaches the edge the world scrolls with him. The thing i'm having trouble figuring out is how the enemies can move freely throughout the world without them getting stuck on the wall, or teleporting when I reach the edge. Also I don't want the enemies to scroll the world, I just want them to be able to move past it. Here is my enemies code.
Here is my Scrolling code inside of the actor that can currently scroll.
If you need to see my world code which is where a lot of the scrolling code takes place, let me know and i'll provide it. Any and all help will be appreciated.
import greenfoot.*;
/**
* Write a description of class Enemy here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Enemy extends Actor
{
int mapX;
int mapY;
public void addedToWorld(World theWorld)
{
World myWorld = (World)getWorld();
myWorld = theWorld;
}
public void act()
{
move(5);
}
public Enemy(int getMapX, int getMapY)
{
mapX = getMapX;
mapY = getMapY;
}
}
public void setLocationWithScroll(int newX, int newY)
{
Background myBackground = (Background)getWorld();
if((newY<200&&myBackground.topBound>0) || (newY>worldHeight-200&&myBackground.bottomBound<myBackground.MAPHEIGHT))
{
int yShift = newY - getY();
}
else
{
setLocation(getX(), newY);
}
if((newX < 200 && myBackground.leftBound>0) || (newX>worldWidth-200 && myBackground.rightBound < myBackground.MAPWIDTH))
{
int xShift = newX - getX();
myBackground.shiftScreen(xShift, 0);
}
else
{
setLocation(newX, getY());
}
}
