Question

I've written the beginnings of a 2D isometric engine using Java. I've got most of the basics covered such as tiling orders and object depth sorting on the map. However, I've run into a problem which I can't seem to solve without making my methods really messy.

The problem is that, in my isometric world, each object is rendered when the tile that the object base is on is rendered on the screen. However, some objects have a large height (such as a building) which can extend from a non-rendered off-screen area into the rendered screen area, and I have no way to detect this as my engine so far relies on object bases being present to render images.

My question is, how would I detect that an object with a large height value should be present in the rendered area while its base is in the off-screen area? I really don't want to be just rendering the whole map (including the off-screen area) as this is very CPU-intensive, so I'm looking for an algorithm or method which allows me to detect this problematic area.

EDIT: Updated the question to visually represent the problem below.

How do I discover when the object's height extends into the renderable area?

Was it helpful?

Solution

Can you modify your concept of 'tile' to include something like an 'envelope'...a rectangle that delimits the maximum height and width? e.g. when the 'large height' object is created / assigned to a tile, you could increase the height of its envelope. Then you only need to render for tiles whose envelopes overlap with the screen.

OTHER TIPS

I would have a method on my object "boolean isVisible(Rectangle2D bounds)". Call this method before sorting the objects and before rending the sorted objects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top