posted new scenario
public class ScrollingActor { int scrollX; public ScrollingActor() { super(); scrollX = getWorld().getScrollPosition(); } //it is important that this is public, and not private. //it gets called by the World every time you want to scroll. //@param amount-- the signed distance to scroll. If negative, //then scroll to the left. If positive, scroll right. public void scroll(int amount) { scrollX += amount; //redo location for changes to take effect. setLocation(getX() , getY()); } //setLocation will also be altered to permit scrolling: public void setLocation(int newX, int newY) { //basically, you set the Actor's location to its location plus(or minus) the screen's scrolling super.setLocation(getX() + scrollX, getY()); }
//doScroll figure out how every ScrollingActor should scroll. public void doScroll() { if(bird.getX() > firstRightScreenMargin) { scrollAmount += someNumber; //(tweak this); } if(bird.getX() > secondRightScreenMargin) { scrollAmount += someOtherNumber; //(tweak this); } if(bird.getX() < firstLeftScreenMargin) { scrollAmount -= someNumber; //(tweak this); } if(bird.getX() < secondLeftScreenMargin) { scrollAmount -= someOtherNumber; //(tweak this); } //now for mouse clicking and dragging if(mouseClicked) { if(mousePosition > firstRightScreenMargin) { scrollAmount += someNumber; //(tweak this); if(mousePosition > secondRightScreenMargin) { scrollAmount += someOtherNumber; //(tweak this); if(mousePosition < firstLeftScreenMargin) { scrollAmount -= someNumber; //(tweak this); if(mousePosition < secondLeftScreenMargin) { scrollAmount -= someOtherNumber; //(tweak this); }