1
\$\begingroup\$

This is my first non-board game and I'm trying to learn a bit about 2D graphics in Java. But I don't know, how should I efficiently implement a camera to make the screen follow the main character. I have a position-fixed, unchanging terrain as BufferedImage on my map and other also mobile and animated entities, including the character itself. Right now I'm using some calculations(x of character - middle of screen) each time on repaint() to draw the level on the correct position from the (0,0) coordinates. But this method does a lot of calculation and drawing, even for the fixed map. Is there a better and more efficient way?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Everytime you move the sprite, move the camera too.

This sounds like it's essentially what you're doing now. If you're encountering performance issues, then you should profile your code to determine where your slow code is. If you're not seeing performance issues, then you don't need to worry about performance issues. Doing a few calculations every frame to determine the camera position is miniscule in terms of processing power.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.