It would appear that whenever I try calling this.createBufferStrategy(3) in the constructor of my GamePanel, Eclipse gives me the error "The method createBufferStrategy(int) from the type Component is not visible". Am I missing something about it?
A BufferStrategy can only be created when the canvas or frame that it will display to is visible on screen. This is one of the main drawbacks of BS (heh) in my opinion.
It is easy to work around however: just call setVisible(true) on the JFrame or whatever prior to createBufferStrategy().
Also, use createBufferStrategy(2
), triple buffering is not necessary.
Ahhh, you don't have a class extend bufferStrategy. You make an instance of it!
He is making an instance of it.
Another alternative is to just use a regular BufferedImage for double buffering instead of a BufferStrategy, at least while learning the ropes.
Doing so has some advantages:
- You do the double buffering manually, so you get to see (and control) what exactly is going on.
- You don't have to deal with BufferStrategy's volatility (it can be "corrupted" (simplification), which you then have to deal with)
It is slightly slower in my experience, but if you're hitting performance problems just for buffering, then you have other problems.
If you would like to learn more, simply google "java double buffering" or some such. There will be many, many