I'm creating a Platform game with 2 playable characters, but I'm having a problem with the Scrolling, since I'm using the Scrolling code from danpost "https://www.greenfoot.org/scenarios/18226" I created a ScrollActor for my first character but my second character can't scroll the world, also tried to make the two of them as ScrollActors but the screen bugged and tried to scroll to each side at the same time, can somebody help me?
//DANPOST SCROLLING WORLD CODE
public static final int WIDE = 600; public static final int HIGH = 400; Scroller scroller; Actor ScrollActor; public PraiaCarry() { super(WIDE, HIGH, 1, false); GreenfootImage bg = new GreenfootImage("Fase da Praia2.png"); int bgWide = bg.getWidth(); int bgHigh = bg.getHeight(); scroller = new Scroller(this, bg, 6000, 400); ScrollActor = new Player1(); addObject(ScrollActor, 110, 290); scroll(); prepare(); }
public void act() { if(ScrollActor != null) scroll(); } public void scroll() { /* int dsx = ScrollActor.getX() - WIDE/2; int dsy = ScrollActor.getY() - HIGH/2; scroller.scroll(dsx,dsy); */ int loX = 200; int hiX = WIDE - 200; int loY = 50; int hiY = HIGH - 50; int dsx = 0, dsy = 0; if(ScrollActor.getX()<loX)dsx = ScrollActor.getX() - loX; if(ScrollActor.getX()>hiX)dsx = ScrollActor.getX() - hiX; if(ScrollActor.getY()<loY)dsy = ScrollActor.getY() - loY; if(ScrollActor.getY()>hiY)dsy = ScrollActor.getY() - hiY; scroller.scroll(dsx,dsy); }