Archived

This topic is now archived and is closed to further replies.

OrangyTang

Moving objects > tile size and prefered techniques..

Recommended Posts

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..

Share this post


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

Share this post


Link to post
Share on other sites
quote:
But in the tile below it is above the ground.


that is where ya lost me... but why don''t you believe kylotan?

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The way I handle this problem is to have an attribute called draw-presence in multiple tiles. I draw by the tiles, first drawing floors, then drawing any sprites that have draw-presence in that tile. But the trick is to only draw the portion of the sprite which falls between the x-axis extremities of the tile.

An example would be useful. Say I am drawing an animation frame of a person who is halfway between moving to the northwest. The map looks kind of like this --

/ \ / \ /
\ / \ / \
/ \b/ \y/
\x/ \a/ \

You''ve got a sprite that is halfway between tile ''a'' and tile ''b''. Both tile ''x'' and tile ''y'' are walls or something that protrudes from the base and you need to make sure that the portion of the sprite in ''b'' gets drawn before the wall in ''x'' but you also need to make sure that the part in ''a'' is drawn after ''y''.

My draw order is left to right and top to bottom -- in this case that means b, y, x, a.

The tiles ''a'' and ''b'' know they have draw-presence for the sprite, so when it comes time to draw ''b'' the floor gets drawn and then any sprites with draw-presence get drawn. But only the portion that lies between the left and right corners of ''b''. Then ''y'' gets drawn, then ''x'' which overwrites a portion of ''b''. Finally the portion of the sprite in ''a'' gets drawn, correctly overwriting ''y'' where necessary.

I hope this makes sense. It adds to the logistics of the thing, but it is the only way I''ve figured out to take care of every possible situation here.

-D

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Oh yes, I forgot to mention. Using this system it is ridiculously easy to do layers. All you have to do is assign each sprite a layer number and use that number to sort when you are setting up the linked-list in each tile that represents those sprites that have draw-presence.

-D

Share this post


Link to post
Share on other sites
quote:

hm, i''m still not totally convinced



well then why dont you just try what they suggest and see if it works ?


"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T

Share this post


Link to post
Share on other sites
aha, that sounds like exactly the solution i''ve been looking for I''ll just have to figure out how to crowbar in object presence into my system - shouldn''t be too hard, although it''ll complicate moving objects around it''ll be worth it. Thanks.


"well then why dont you just try what they suggest and see if it works?"

Because i worked though it many times on paper and could always find cases that it would fall over in. Try it if you want to and you''ll see yourself.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I need to amend my previous statement. The procedure I outlined above works in most cases. However, if you want a bridge/arch or something to work completely correctly, then you need to put the top part in another draw iteration (one that is drawn after the normal one is completed). This is probably what previous posters meant when they said that you should use ''layers''. Determine a height in pixels for your map and then any sprite that is taller than the height needs to have presence in the top map as well. This height is also the number of pixels you need to offset the second map when you draw it. This concept can of course be extended to encompass any number of stories. X-com had three or four, for instance.

-D

Share this post


Link to post
Share on other sites
There is a concept that I''ve always used...

With a simple version 2 layers exist, background = z of 0 and foreground = z of 2. Draw order is layer 1, sprite or null, then layer 2 or if sprite over layer 2(with layer 2 drawn to null). Moving on to a background tile with the "Z change" property into a tile with a "layer 2 Z" causes your sprite position to become x,y,++z. Moving from a tile with a "layer 2 Z" into a "Z change" tile causes the sprite position to be x,y,--z.

Virtual position = x,y,z
Screen position = x,y
Sprite draw order = (spritez + 1)
If spritez = layer2z
{
    layer2z = 1

}

Just draw it back to front, or 0 to 2 as they mean the same.

Share this post


Link to post
Share on other sites