Bringing Blocks To The Background?

Started by
2 comments, last by Alberth 7 years, 6 months ago

I've been working on a game in Java and I'm having an issue with the blocks which the player can place down in the game. I have specific types of blocks which are meant to be for decoration. They're basically walls. The player can walk through them - no interactions are made between them.

The problem is, the only way I can do that is to draw the walls before I draw the interactive/solid blocks. That means I'd need to have 2 for loops in my render method - one to iterate over my block storage list and ONLY look for walls, and the other one to render the rest of the solid ones.

This causes about a decrease of about 200-250 fps. Is there another way I can go about rendering the walls behind the player/everything else?

By the way - I'm not using any libraries, and I'd really honestly rather not.

Thank you.

Advertisement

Why not just draw both blocks in the same loop? For a given tile or screen location, draw the background one first then draw the one in the foreground.

This causes about a decrease of about 200-250 fps

This means nothing. Frame rate reducing by x frames is completely useless as a metric to go by.

Unless your current performance is actually a problem, ignore it and move on to the next task. You can always optimize things later if there's a need for it.

Hello to all my stalkers.

The problem is, the only way I can do that is to draw the walls before I draw the interactive/solid blocks. That means I'd need to have 2 for loops in my render method - one to iterate over my block storage list and ONLY look for walls, and the other one to render the rest of the solid ones.
Any reason you cannot have two lists, one for background blocks and one for foreground blocks?

This causes about a decrease of about 200-250 fps.
As Lactose! said, the number is meaningless.

To see, if you have 1000fps, you still have around 750fps now, which means you can draw everything around 12-15 times for one frame at the screen. If you had 251 fps, you now have a problem, as 1fps is not so much for playing. If you can still play smoothly, just ignore the problem, it's likely not relevant at all.

Don't try to be optimal every step of the way, it costs too much time. It's much more effective to just build things, and once you have a problem find the cause and do a local fix.

Just delete the fps counter, it's only distracting.

This topic is closed to new replies.

Advertisement