Moving objects > tile size and prefered techniques..

Started by
14 comments, last by OrangyTang 22 years, 1 month ago
Ok, first post yadda yadda.. I''m involved in a 2d game but with a ''fake'' 3d look and movement. Its not actually isometric but that slanty top down view seen in the early C&C, phantasy star etc. Although i say fake 3d, objects can still occupy any position in 3d space, but all the graphics are 2d parts (sprites etc.). All fine and dandy, sort and draw from the back forwards you''d say, but how exactly would you draw objects that are larger than a tile in dimensions. Tall objects wouldnt be a problem, since they can be drawn at the same time as an equivilent smaller object, as long as the background is already drawn. But how about deep objects? The sprite would have dimensions the same as a tall sprite, but obviously needs to be handled differently. Since we''re allowing overhangs, bridges etc. the sprite needs to be drawn under the bridge, yet over the background. Although all the time it belongs in the tile south of the objects in question, even though it overlaps them. Ideas people? I''ve a few, but i''d like to hear others approaches first. Any help would be welcome. --- Todo: insert witty sig..
Advertisement
Providing you draw them from back to front and sort them by their position at ground level, there''ll be no problem, whether tall or deep.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
er, i''m sure there will be..

For example, an object that is pretty flat and large.. say a snooker table on wheels (terrible object example but you know what i mean) with the longest edge going north/south. Say its about 3 tiles in total size, and about 2 tile width.

But it ''exists'', as in the center point/origin/whatever in a certain tile, extending up and down, left and right to a lesser extent. Now push the thing so its view is obscured by an bridge. At the first/top tile that it occupies it is above the ground and below the bridge. But in the tile below it is above the ground.

So at what point should it get drawn? If i draw tiles top down, depending on what tile it occupies its going to go above the bridge or under the ground on the tile below.. And if i do both then it''ll just appear on top. Am i being clear or just confusing matters..?
quote:But in the tile below it is above the ground.

that is where ya lost me... but why don''t you believe kylotan?
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
I''m doing a bad job of explaining this, a pen and paper would be so much easier..

Back to front sorting simply doesnt cut it. Certain cases (like tall or deep objects) cause problems when they need to fit inbetween levels in the map, like underneath a bridge and above the ground. Deep objects need to be handled like this. However tall objects need to occupy the same space on the screen but in a different order. Instead, they need a different drawing order.


From directly above:


A: BBBBB - bridge with floor underneath
B: .1.2. - floor, with objects 1 and 2 above.


So when viewed from an angle, if ''1'' is deep, it needs to go underneath the bridge, and if 2 is tall it needs to go ''over'' but is infact infront of. Object 1 would require the floor drawn first (row a and b) then the object, then the bridge. 2 requires the floor, then the bridge, then the object. But i can''t see a good way for the renderer to discriminate between the two cases in any kind of a good way. And if they are both on the same tile then it gets really messy since the objects need to be drawn inbetween drawing the different layers.

And because i want to be able to support objects of any height or depth, i can''t just check the surrounding squares for cases like this, since that would take huge amounts of time to allow very large and deep objects..
you''re right.
but your wrong too.
does that make sense?

anyway if you sort your objects correctly then you won''t have a problem.
I''ll use the bridge/table scene:
first of all you sort the objects from down to up (Z), then from back to front (Y) and then from left to right or right to left (X).
and in code:
if( a.z == b.z ){
if( a.y == b.y ){
return (a.x < b.x);
}
else return (a.y < b.y);
}
else return (a.z < b.z);

now there is no problem, your bridge is always over the table.
and if you use your x,y,z coords correctly there won''t be any problems in the future.

just remember that a single x,y,z coord isn''t always enough for an object

cheers

I am what I am, more or less
and my site rocks
www.geocities.com/roam_fire
I think
I am what I am, more or less :)and my site rockswww.geocities.com/roam_fireI think
hm, i''m still not totally convinced, i''m sure i thought of that before and found cases it won''t work for. But i''ll try it first and see how it goes.

So the next question becomes how to store all the objects for efficiency, i was thinking of a 3d array with linked lists dangling off of it, probably only creating the linked lists when needed to cut down on wasted space. Or is there a more commonly used idea/method?
Separating things into layers solves most ambiguities quickly.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
you might also try to split the object into tiles, so if the so called table is 3x2, you split it into 6 tiles that you put back together at runtime, so the part obscured by a bridge is drawn before the bridge, but the part that isnt is drawn later.

i''ve already planned a certain amount of layering to sort things quicker, but simply splitting the object into pieces doesnt work because if the objects are moving (which they will be) then the edges may or may not fit properly and could just complicate matters..

This topic is closed to new replies.

Advertisement