Slick 2d scrolling off screen

Posted by Peter on Game Development See other posts from Game Development or by Peter
Published on 2012-06-05T19:41:18Z Indexed on 2012/06/05 22:48 UTC
Read the original article Hit count: 254

Filed under:

I have something scrolling in and out of the screen. Now when it goes off screen, I want it to scroll into the screen at another location. What I do is I grab the last pixels at the screens edge using g.copyArea and then g.drawImage on the edge of the screen. And then I do a g.translate to create room for the next row which is next render cycle.

My problem is that I get a single pixel row, which is not copied onto the canvas. Where as I want each row to be added and then translated, so that the image that scrolled off screen is recreated on the other side of the screen.

Here is my code, maybe there is a better way of doing this, open to any suggests, cause I'm totally stuck

@Override
public void render(GameContainer gc, Graphics g) throws SlickException {

    //g.setClip(0, 0, 300, gc.getHeight());
    g.translate(0, y);
    g.drawImage(image,0,200);
    g.resetTransform();
    //g.clearClip();

    g.copyArea(rightImage, 0, gc.getHeight() - 1);
    g.drawImage(rightImage, 300, 0);
    g.translate(0, y);

    y=y+3;

}   

© Game Development or respective owner

Related posts about slick