Hello everyone,
Im pretty new at this game development but familiar with programming. I had some experience with java also. Watching tutorials in the internet, im getting stucked with this rendering point of the simple 2D games. I use actionListener in the main class, attached it with a timer (0 second delay) and in the actionPerformed(ActionEvent e) method, i first calculate the balls position, collision or the speed (mainly game pyhsics) and after those i call the repaint(Graphics g) method. In this method i draw the background first, then i draw the ball and the paddles.
The problem is, im using images to have a better visualization. But when i create a JFrame which is 1280x760, the game starts not to move smoothly. When i cancel the background drawing, it starts to get far more better. But i still don’t get that there are much more bigger games which are working pretty smooth in this computer like CoD or Assasins Creed, this simple background slows my game. What should i do to fix it? What if i got 100 balls to move in this pong game? Or what if this background has to change in every frame?
Can someone please guide me? Im totally lost what to do. Looked for lwjgl or generally OpenGL but it looks pretty complicated to start. I mean im trying to make simple games like pong, snake or flappy bird. But i really hate rectangles, just wanna use images or sprites instead of them. And now stuck with it…
SOLVED: The problem is this line of code in the repaint method
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
when i disable it, the animation is perfect!