Archived

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

Scrolling games theory questions...

This topic is 5672 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I have a good chunk of my 2d engine done, it just needs polishing and a nice implementation to handle 2d scrolling games... the thing is, I can read example code all day for scrolling, the code makes sense but building a good implemenation that a game engine can use never does. I mean do the enemies in a game have world coordinates? etc.. etc.. things like this. does anyone have a good example of such an implementation or can answer my stupid simple questions like: (So you have a scrolling background fine and dandy but..) How do the enemies fit into the level? What about the character is his x,y always the middle of the screen? What about when he gets to a special place in the level, that held in a tile? I have seen some engines where the tile struct holds lots like: The type of tile and things on top such as objects and enemies etc...if u do this though wouldn''t your enemies have to be the same width and height as your tiles? See probably simple questions to you all, but these are the things I just cannot seem to uncould my mind with. Any help etc.. is greatly appreciated. Thanks, -Shane

Share this post


Link to post
Share on other sites
First, figure out what exactly you need out of your game engine. Things to think about for your world:

- Collision between moving object and the world (just per tile, per pixel, preset slope types etc.)
- Different tile types, do you need stuff like water, sand etc. that affect moving objects above them?
- how are you going to handle collision between moving object? and how accurate does it need to be?

My method for scrolling - every object, tile, graphic etc. has a world coord. Then you have a camera that defines whats currently onscreen. To draw your screen you have to take your objects world coordinates, alter it according to the camera position to get the objects screen coords. Then you draw the object. As the camera moves, every time you redraw the screen you calculate the screen coords again.

"How do the enemies fit into the level?"
However you want them to. You could just store them all in a big linked list or array. But the key point is that this is independant of the camera position and really has nothing to do with the scrolling.

"What about the character is his x,y always the middle of the screen?"
Simplest way would have the character walk around just like the opponents, but have it contantly adjust the camera position so that it is near the center of the screen.

"The type of tile and things on top such as objects and enemies etc...if u do this though wouldn''t your enemies have to be the same width and height as your tiles?"
Not really, your enemies could be an entirly different structure and handled differently. But first you have to decide what exactly you''re aiming for..

Hope that helps, but i''m not really sure if that was what you were asking about...

Share this post


Link to post
Share on other sites
For one complete program (open source) that addresses all your questions, you can visit http://gamedev.sf.net for a look at The Scrolling Game Development Kit.

Quickie answers (the way the kit addresses your questions):
All sprites (things that do not have to align to tile boundaries) have coordinates measured in pixels from the top left corner of the layer on which they reside.
The player is just another sprite, but unique in that the scrolling follows it when it can.
Each tile is one byte (only 256 possible tile types per layer allowed in this engine). To accomplish other special meanings for tiles, there are tile groups and solidity definitions that group tiles into different shapes and allow certain interactions with particular tile values. Also, "Special Functions" are structures separate from tiles, but are defined in tile coordinates. They respond when the player sprite touches them. Whereas tiles are simply a 2-D array of bytes that fill the map, Special Functions define their own location and take longer to locate given a location (have to look through them all to find one at this location). That way tiles take up minimal space, and special functions only take up space according to how many there are and how complicated they are.

In a previous engine I wrote, each tile was 4 bytes (or was it even less -- I forget) and I really packed those bits with information to allow special functions in each tile (only 64 tile graphics were allowed I think). But that''s a lot more wasted space, even if it is a bit speedier to locate the function for the current tile.

OK, this is swiftly turning into a non-quickie answer . If I had to design it again, I might allocate 2 bytes per tile and have at least one of the bits indicate whether there was a special function on the current tile (don''t look for a function if there isn''t one), then allow maybe 8192 tile graphics and have a bit or two to spare for whatever.

"All you need to do to learn circular logic is learn circular logic"

Share this post


Link to post
Share on other sites