Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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;

}   
share|improve this question
If you are scrolling it back in at another boarder of the screen, I think it would be much easier (and less process-heavy) to just copy the whole image/object as it scrolls out, and have that copy scroll in on the boarder it should scroll in at. --- If you are scrolling it back in somewhere inside the view area, you can use a similar technique, by copying the area of scenery behind the scroll-in-point and re-rendering it above it. – TheLima Jun 5 '12 at 22:19
Thanks for the fast reply, but it's bigger than the screen in total and it's dynamic content. I could reconstruct it like I constructed it at the first screen edge, but I think that will take a lot more cycles. When I copy 20px slices to the other screen edge it performs nicely, but those slices don't stamp onto the background, they stay at one position or they scroll while the content changes. – Peter Jun 6 '12 at 5:51
Also tried drawing onto another image, since I doubted the existence of any canvas on the main Graphics object :-) But I got the same result, moving or static segment, but no copies of segments together with scrolling action. – Peter Jun 6 '12 at 6:01
As for the other edge of the screen, I current build up a large chunk and scroll that, but ultimately I have the same problem on this first edge of screen, since I want to render slices of dynamic content and scroll those in and out of the screen. – Peter Jun 6 '12 at 6:09
I kind of got it to work a bit, by translating, drawing and flushing onto another image which I placed on screen :-) indeed very slow.. thinking about your suggestion grabbing the whole screen and then paste it outside of the screen to let is scroll in again. Don't know, there must be a better way, anybody out there, any hints? – Peter Jun 6 '12 at 16:28
show 1 more comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.