Game Programming and Development Tools

2d clipping w/ DirectX 8 – briandra2

briandra2
Member

Posts: 15
From: Brookfield, WI, USA
Registered: 06-28-2001
All right, I'll do my best to explain this I'm using c++ and Directx 8.0.

You know how in old 2D adventure games, the character can appear in front of and behind of objects? When the character appears behind an object, you don't see the part of the character the object is in front of. How did they do that? Is that some sort of complex clipping programming? Any ideas on how you would do this with DirectX where the clipper objects no longer exisit? Again, I'm talking total 2D here, not 3D and not some weird blend of 2D and 3D like final fantasy 7.

Thank you,
Brian

CobraA1

Member

Posts: 926
From: MN
Registered: 02-19-2001
It's a combination of two things: sorting and transparency.

First, everything has to be sorted somewhat, and there seems to be at least two methods for this.

The first method is layering - RPG Maker 2000 does this - certain tiles are above the player, other tiles are below.

The second method is using a real sort that depends on the position of the object. Isometric games such as SimCity 3000 probably do this. I'm not sure about the details, but I imagine they sort using a defined "base point" that's at the center of the object at the bottom (as if they were in 3D space, although they're really not).

After sorting, the objects are drawn from back to front, so the objects in front overlap the object in back. To allow for arbitrarily shaped objects, they use a transparency mask to determine whether or not a pixel is drawn.

Usually the player is two tiles high, so that part of the character can disappear behind something. It's simply overdraw - the object is drawn over the character.

I hope this is clear enough .

MadProf
Member

Posts: 181
From: Larnaka, Cyprus
Registered: 01-24-2001
hi!

In a semi-game engine I was writing a few months ago, I had a tile based map, with the player on it, and walls on the map which would block out the parts of the player when it got close... the way i did that was (sudo-code):


for (y=0;y<map_height;y++) {
for (x=0;x<map_width;x++){
if ((player_y == y)&&(player_x == x)){
draw_player(x,y);
}
if (map(x,y) == WALL){
draw_wall(x,y);
}
}
}

something like that. It was in python, so looked nothing like the above, and was more complex than that... but thats the main idea.

God Bless,
Dan

------------------
7 days without prayer makes one weak.