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

2012/8/21

Using a screen buffer

SPower SPower

2012/8/21

#
Hi all, Is there a fast way to use a screen buffer, and creating a GreenfootImage out of that? I can only come up with something like this:
private Color[][] buffer;
// create the buffer.
// at the end:
for (int x = 0; x < getImage().getWidth(); x++) {
    for (int y = 0; y < getImage().getHeight(); y++) {
         getImage().setColorAt(x,y, buffer[x][y]);
    }
}
which is pretty slow. Thanks for the help.
danpost danpost

2012/8/21

#
Where is the buffer getting its colors from?
SPower SPower

2012/8/22

#
I'm trying to use this along with ray casting, so I have a for loop where I look at every vertical 'slice' of an image, fire off a ray, and draw a line if neccesary. So the buffer gets its colors from this:
for (int y = lineBegin; y < lineHeight; y++;) {
     buffer[x][y] = color;
}
outside the big first for loop (the one looking at every slice), I have the code I posted above.
danpost danpost

2012/8/22

#
But, what is the variable 'color' and where does it gets its value? I wanted to know the origin of the values that 'buffer' contains? (you went back one single step; but now, where does 'color' get its value? etc.)
SPower SPower

2012/8/23

#
I'm sorry, but what does this add to my question? To repeat, I wanna know if there's a faster way than doing it like the code in my first post here.
davmac davmac

2012/8/24

#
If you're looking for a faster way to manipulate an image, your only option is really to use getAwtImage() and then manipulate the BufferedImage that is returned. For instance, just using the setRGB(...) method in BufferedImage may be slightly faster than using setColorAt in GreenfootImage. You could also use other methods in BufferedImage to manipulate the image data directly, which might be faster again (but which is also complicated).
SPower SPower

2012/8/24

#
@davmac thanks, I'll look at that. I thought maybe there is a hardware accelerated method, but apparently not.
You need to login to post a reply.