Jump to content
  • Advertisement
Sign in to follow this  
null;

Bringing Blocks To The Background?

This topic is 801 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Edited by Debz

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!