Moving objects > tile size and prefered techniques..

Started by
14 comments, last by OrangyTang 22 years ago
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
Advertisement
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
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
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.
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
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.
"Who are you, and how did you get in here?""I''m the locksmith, and I''m the locksmith."

This topic is closed to new replies.

Advertisement