Questions tagged [bufferstrategy]

The BufferStrategy is a Java class representing the mechanism used to organize complex memory on a certain AWT Canvas or Window. Use this tag for general questions related to creating or managing a BufferStrategy.

Official Documentation:

75 questions
14
votes
2 answers

Java bufferstrategy graphics or integer array

When doing 2D game development in Java, most tutorials create a bufferstrategy to render. This makes perfect sense. However, where people seem to skew off is the method of drawing the actual graphics to the buffer. Some of the tutorials create a…
Kabistarz
  • 141
  • 4
9
votes
1 answer

Is there any reason that default buffer sizes are 4096?

I often see 4096 used as a default buffer size all over the place. Is there any reason why 4096 was selected as opposed to another value?
myermian
  • 31,823
  • 24
  • 123
  • 215
8
votes
1 answer

Adding textfield to Graphics in java

Does anyone know how to add JTextField into Graphics name bufferstrategy.getDrawGraphics? Tryed to pain it into graphics, something like this: private JTextField Input = new JTextField(); BufferStrategy bs = getBufferStrategy(); if (bs == null)…
null
  • 87
  • 1
  • 7
3
votes
3 answers

How to determine reasonable number of bytes to read per read system call?

I am playing with file reading/writing but have difficulty deciding how large to make my read buffer for the "read" system call. In particular, I am looking at "http://pubs.opengroup.org/onlinepubs/009695399/functions/read.html" It doesn't seem to…
Dmytro
  • 5,068
  • 4
  • 39
  • 50
3
votes
0 answers

BufferStrategy show() method is taking upwards of 50 milliseconds to complete for a double buffer, why is it so slow?

Calling the setup method starts the timers that i have, the one I'm having problems with is render, which takes upwards of 50 milliseconds to complete. far too long for only a double buffer. public void setup() { hB = new…
TopQuark
  • 25
  • 1
  • 5
3
votes
2 answers

How to draw images on transparent window?

I'm trying to draw Images with Graphics2D on JFrame. But this code only displays blank background. How to do that? Java Version: SE-1.6 IDE: Eclipse My code looks like this: import java.awt.BasicStroke; import java.awt.Color; import…
django
  • 33
  • 3
3
votes
1 answer

How to create bufferstrategy in a class which extends JPanel

I am beginner in Java and I am having difficulties creating bufferstaregy in a class which extends JPanel but not canvas. Can some one show how to add buffer strategy here. I wrote very simplified code which illustrates my problem. I move rectangle…
Fataho
  • 99
  • 3
  • 15
2
votes
1 answer

When using createBufferStrategy() in java, does it help to have more than 2 buffers? Is there a downside?

It seems like most people recommend just using 2 or 3. Is that just because more than 3 takes up too much processing power or something (forgive me I'm kind of new to this)? In what kind of programs would you use more than 3 buffers? 2 or 3 works…
2
votes
1 answer

What happens when I call "BufferStrategy.show()"?

Graphics g = bs.getDrawGraphics(); g.setColor(Color.BLACK); g.fillRect(0, 0, getWidth(), getHeight()); g.dispose(); bs.show(); Does calling bs.show() actually display the buffered frames? If so, how? It simply says that it makes the next available…
sodaluv
  • 449
  • 2
  • 9
  • 22
2
votes
1 answer

Component must have a valid peer - BufferStrategy

First off all, I know questiones like this has been asked before, but no answers seem to fix my problem. I am working on a little game, and for some reason java returns an IllegalStateException whenever I try to create a new bufferstrategy. I am…
ItzBenteThePig
  • 696
  • 1
  • 9
  • 19
2
votes
1 answer

Buffer Strategy IllegalStateException

I know this has been asked before but I still can't get it to work. public class GUI extends JFrame implements Runnable{ public static JPanel contentPane; public static Graphics2D graphics; public static BufferStrategy bufferStrategy; …
Bloodwing
  • 25
  • 4
1
vote
1 answer

Java Stuttery/Flickery/Laggy Animation In Game

To be honest, I'm not to sure how to describe my problem, you can see it here. In that video of my code running, it is most prominent in the first few seconds. Occasionally and randomly I am getting a weird flickery/stuttery/laggy glitch in my…
toadless
  • 147
  • 10
1
vote
0 answers

Rectangle not being drawn on screen (Java GUI)

I'm currently watching RealTutsGML's tutorial on Java game development. In his tutorial, a black rectangle is drawn on the screen; however, after completing all the steps he has completed, a black rectangle is not drawn on my screen. I've researched…
Crazyww1
  • 11
  • 1
1
vote
0 answers

Is it not a good idea to use Graphics to clear the screen every frame? (Java)

So after looking at multiple ways to paint or draw things onto the canvas/screen, I tested out my own way that seems to work, no problem. I simply just g.clearRect(0, 0, width, height) on an update method that is put in my game loop so that the game…
1
vote
2 answers

Why is my BufferStrategy throwing a NullpointerException and how do I fix it?

I've been trying to make a 3d game and for some reason my code is throwing a NullPointerException. The error I'm getting is: Exception in thread "Thread-3" java.lang.NullPointerException at Display_3d.render(Display_3d.java:73) at…
1
2 3 4 5