Hi there,
I’d like to program a game in which music plays an important role. Thus I need to write kind of a spectrum analyser. Just some bars changing their height in time. I want it to run in its own window. What I’ve done by now was to define a JPanel and to calculate the height of the bars. Then I draw them as rectangles into an image and afterwards I use drawImage to make the image visible.
My problem: this routine uses so many resources that I can hardly stop the program, because the window doesn’t react (or at least very slowly). I think this can be done much better, especially because I change at most the height of two bars per frame. Therefore it should be sufficient to redraw at most eight pixels (every unit of a bar is 2x2 pixels big) plus a small string in the corner, maybe.
Now I don’t know how to realize this idea. I think I have to go on painting the whole image into the imagebuffer, because a refresh of the whole window could be necessary (after being in background and so on). But with drawImage I cannot paint single pixels onto the screen. And even if, is it the best way to do it? And is it sufficient to write the graphical data straight to the image-object? I’ve found a lot of solutions to make this operation faster (and more difficult), but after all the time killing procedure isn’t the writing to the buffer but making the buffer visible, right?
I’m looking forward to your commands and suggestions :).
Reilly