This site requires JavaScript, please enable it in your browser!
Greenfoot back
Spacer
Spacer wrote ...

2024/4/6

my scrolling background ends up getting pixelated every time

Spacer Spacer

2024/4/6

#
i want my background to scroll horizontal. This is my Code
public void drawBackgroundImage() {
    if (imageCount < -bgImage.getWidth()) {
        imageCount += bgImage.getWidth();
    }
    int temp = imageCount;
    getBackground().drawImage(bgImage, 0, temp);
    getBackground().drawImage(bgImage, 0 , temp + bgImage.getWidth());
    getBackground().drawImage(bgImage, 0, imageCount - bgImage.getWidth());
    } 
It does but after a few seconds the background starts getting pixelated for a short period and after that the right non pixelatedbackground comes back. Can somebody tell me what i have to change?
danpost danpost

2024/4/8

#
Spacer wrote...
i want my background to scroll horizontal. This is my Code << Code Omitted >> It does but after a few seconds the background starts getting pixelated for a short period and after that the right non pixelatedbackground comes back. Can somebody tell me what i have to change?
I think you have the coordinate parameters in the drawImage method calls backward. Plus, lines 7 and 8 are kind of conflicting with each other. I believe you have one too many drawImage calls.
Spacer Spacer

2024/4/9

#
Ok but what do i have to change now?
danpost danpost

2024/4/10

#
Spacer wrote...
Ok but what do i have to change now?
I would say remove line 8 and put the zero parameter on lines 6 and 7 last.
Spacer Spacer

2024/4/11

#
I think i described it wrong, i wanted the background to move vertikal, and it already does. I removed the 8 line but it still pixelates for a short period of time. I don't know if maybe the picture is too small.
danpost danpost

2024/4/12

#
Spacer wrote...
I think i described it wrong, i wanted the background to move vertikal, and it already does. I removed the 8 line but it still pixelates for a short period of time. I don't know if maybe the picture is too small.
For vertical scrolling, you will need to change all getWidth calls to getHeight calls. The best image size is the scenario window size, requiring only two drawImage calls. Scaling may be all that is needed. If still pixelating, may be due to transparencies within the image. Try drawing the image on a full white filled image (of same size) and using it
Spacer Spacer

2024/4/12

#
It finally worked!! Thank you :)
You need to login to post a reply.