How to do a 2D engine

Hey guys. Up til now, I have been working with 3D programing. At this point, I need to figure out how to make a 2D engine. Basically, the type of game I am aiming for can’t have any sort of “zone loading” that 3D graphics require. I am kinda confused about something… do all 2D engines revolve around tiles? I understand how tile-based rendering works… in fact, I’ve used it in directX before. It seems like tiles wouldn’t work for a large world, however. A good example of what I am trying to accomplish would be Ultima Online. There is no zone loading throughout the entire game. Does that type of game use some sort of dynamic tile loading, or what? If tiles are not used, then how do you determine what to render onto the screen and collision detection?

I hope what I am asking is clear, if not, lemme know and I’ll try to clarify. Thanks in advance, everyone. =)

[This message has been edited by Cebu (edited 05-14-2001).]

Er, um, anyone? Need some help here =)

I don’t know how UO does their rendering exactly, but even though there is no zone loading, you can tell where the lines are between server zones if you know what to look for.

If you are a tamer and have a lot of pets, you will often notice that they refuse to cross “server lines.” There have been times where you can be running around and see a whole line of pets by the server line.

My guess is for the graphics they only load in what is needed for the immediate area and a bit more around that. Lots of times if you are going through a new area you can notice some hard drive activity, but when you run back through that area again it’s not as noticeable.

Hi!

I coded something like that some years ago. perhaps some form of Raycasting would be god for you. I think you have a 2d-map of your area. place the camera on the point you whish (on the MAP!!!), and then (I say draw now, but I mean think it on the map ) draw a line from cam through lookat until the max_viewing_distance is reached. this is the height of a triangle. say cam is point C. and the viewing angle is gamma. now you have to find A and B. “draw” a line orthogonal to the cam-lookat line with max_viewing_dist from cam away through the first line. now draw a line with gamma/2 (angle between this new line and first line) from C to the second line and you get A. repeat on the other side: we have B. you only have to render the objects in this triangle, cause the outside part of the world isn’t visible

I know it’s a strange explanation, but if you have questions, don’t hesistate to e-mail me. I couldn’t feed you with code (cause i don’t have one. the prog I did was a real raycast-engine (wolfenstein-like) without any 3d-acceleration, done in TurboPascal…5 years ago… )

hope i could help.

Bastian

Like Deiussum suggested, a good idea would be to load tiles around the area you’re in, and as you move to new areas, load new tiles around it in the background. Easier said than done, of course.

But it may still be possible to keep the entire map in memory. That could depend on what you mean by “large world”, though. And BTW I have no experience in writing 2D games, or even playing UO or similar online games, so my ideas may not be as good as I think they are.

A 4096x4096 map with one byte per tile would take just 16MB. This can be quite a large world, depending on your tile size.

You can make it even more memory efficient by using some sort of quadtree or hierarchical map, where large areas (such as sea, desert, grassland) will be represented by repeating tiles (with some variations), and details will then be added onto them.

Some details - like plants, rocks,… - could be generated pseudo-randomly, from a known seed (like the location of the tile).
Others, like large structures could be represented by a reference to a tile map of that structure (assuming that the structure appears several times in the world), that will be put over the generic tiled area.

I would say that quadtrees are the way to go. Try a search on google.

Yeah… I know about the server “lines” … but that’s really an issue of dynamic objects instead of static graphics. It was always fun to go cruising along in the wilderness and all of a sudden cross a line and lag like crazy cause there’s a lot of people in that server… hehe.

I never really thought about ray tracing and quadtrees for 2d graphics. I know about them in 3d… but I guess there’s no reason they wouldn’t work in 2d as well. I guess at this point it just comes down to how I want to represent the graphics, via tiles or as vertices in memory referenced by a quadtree or something similiar.

Really I was looking for an excuse to go one way or another, but I need to just talk with my co-developers and hash out the pros and cons if each technique. I guess a lot of math will be in order to determine how much stuff can go in memory, etc. Hmm.

Anyhow, thanks a bunch guys… you’ve got started on how to thing about going about this. I really appreciate your time, and I’m sure I’ll be asking more quetions in the future when I run my head into something else =)