Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9163851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:32:32+00:00 2026-06-17T14:32:32+00:00

Explanation: EDIT3: MASSIVE CLEAN UP as this was not clearly explained. I’m trying to

  • 0

Explanation:

EDIT3: MASSIVE CLEAN UP as this was not clearly explained.

I’m trying to build up a 2D level out of tiles and entities. Where the entities are for example trees that can be cut. I need to store the data (how many chops are left for example) for each entity. I want them to have a more dynamic position (doubles) and a more dynamic sprite-width and height. My tiles are 32×32 pixels whilst my trees are not going to be one tile but a sprite with greater height than width.

I want objects that are closer to the top of the level to be drawn before the other objects. In this case a character behind the tree will cannot be rendered in or in front of the tree. This case also applies to other objects of the same kind (like trees).
I think it might be too inefficient to loop through the entities and calculate each entity’s position since there may be a LOT of entites in the level.

As I’ve done some research I found that certain libraries allow the storage of both the object and it’s position in a MAP (BiMap in google’s Guava).

Questions:

  • Is this an inefficient manner.. but are there some changes that can
    be applied to make the rendering more efficient (if so, what could be
    optimized)?
  • Or is this an inefficient manner to render the entities and is
    there a better way (if so, what other methods are there in Java)?
  • Or is there something else that I haven’t listed?

EDIT2: I looked through the link I’ve posted in the edit below.
It seems that Google’s Guava (I think that’s all correct) has BiMaps. Is there an equivalent to this in regular Java? Otherwise Google’s Library will probably be able to fix this for me. But I’d rather not install such a huge library for this one interface.

At last:

It’s very much possible that the answer has been right in front of my nose here on StackOverflow or somewhere else on the internet. I’ve tried my best searching but found nothing.
If you’ve got any suggestions for search queries or any relevant links that might be of use to me I would appriciate it if you’d post them in the comments.

Thanks for taking the time to read through this/helping me 😉

EDIT:

I have looked at; Efficient mapping of game entity positions in Java .
I think it’s narrowly related to this question. But I think it’s just not what I’m looking for. I am going to look through the second answer very closely since that might be able to solve this for me.. but I’m not sure.

SOLUTION

The solution is to have an array, arraylist or another manner to keep track of your entities. Every tick/update you’ll take all the object’s Y coordinates and store them in another array/arraylist/map/other with the same size as where the entities are stored in. On every equivalent position to the entity you’ll store it’s Y. Then you’ll order it with another loop or using http://www.leepoint.net/notes-java/data/arrays/70sorting.html .

Then when rendering:

for(int i = 0; i < entityArray.length; i++)
entityArray[i].render();

Off course you’ll render it more efficiently by rendering only whats on or near your screen.
But that’s basically how one does this in 2D top-view/front-view.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:32:33+00:00Added an answer on June 17, 2026 at 2:32 pm

    In my own 2d game attempts I come up with the following solution:

    • use an enum to specify different types of objects in game and give them priorities (sample order: grass, rivers, trees, critters, characters, clouds, birds, GUI)
    • make all visual objects implement interface which allows for getting this DrawPriority enum
    • use a sorted implementation of list with comparator based on the enum
    • use the list to draw all elements

    That way the order computing is not very expensive, because it is done only on Visual Object insertion (which is in my case done while loading a level).

    .. And since you will already using a comparator, do a x/y comparison when the enum priority values are the same. This should solve your y-order draw problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add explanation between cells. I'm experimenting with sections, trying to make
I use this to read a widestring out of the cmd (Windows Shell). var
Please refers to the edit portion for my explanation. This is a bit long
Explanation for people who don't know: this syntax means to Firefox : use the
EDIT: Removed code/explanation because this project has been given again and students can easily
EDIT: I rephrased the question because I have not explained well. Let's see if
This one will need a bit of explanation... I want to set up IIS
I want to write a rule that looks something like this: foo.out: (out of
Here is an example of my code and an explanation what I am trying
By way of explanation, take this value type in C#: struct ObjRef { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.