Advertisement Jump to content


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


2d arena's larger than a single screen - how?

This topic is 6329 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

I''ve managed, in my limited ability, to create a little 2d shooter game in much the style of the ancient SpaceWar. I want, however, to expand beyond this. While, with what I have, you can fly your ship around an arena the size of the screen, I want to be able to fly around a much larger space, keeping the players ship in the middle of the screen, until the edges of the arena are reached, at which point the screen will no longer scroll across the arena, but the ship will move from the centre, until the player moves back away from the edge. (if you''ve had a go of a shareware game called inner space, you''ll have a good idea what I want to create). Any pointers on how to work on this, or ideas of places to get information?

Share this post

Link to post
Share on other sites
It depends on your background. If you use a big bitmap, as I did in my old rally racing game, only change the offset variables like this:

int xofs, yofs


xofs = player.x - SCR_W / 2
yofs = player.y - SCR_H / 2
if (xofs < 0) xofs = 0
if (yofs < 0) yofs = 0
if (xofs > IMG_W - SCR_W) xofs = IMG_W - SCR_W
if (yofs > IMG_H - SCR_H) yofs = IMG_H - SCR_H
drawbitmap(xofs, yofs, WIDTH, HEIGHT);


Something like that. If you''d like smooth movement (sliding slowly until it hits a border) takes some more rows of code, but this will work for simple applications.

If you use stars, or any objects, with positions stored in a list, only check what objects are on the screen (with the above offset variables). That''s all!

Share this post

Link to post
Share on other sites
Ok, what you need to understand here is a concept not a bunch of code. Think like this, that you have a "worldspace" that is simply but the whole world, and a "viewspace" or "viewport" that is a portion of the world and most proably you screen.
What you need todo is to translate from worldspace to viewspace,
i.e to look at the coordinates 100,100 the upper left corner of your "viewport" should represent exactly that when you render the world.

nice ascii pictures following

| |
| world |
| ___ |
| V.P-> | | |

Thats the basic idea the equations needed can easily be figured out using a notepad and doing some drawings similar to the one above and playing around a bit with it, the trick is to not move the world but to move the viewport

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Most games use rendering to achieve unbelievable map sizes. While it''s true you can use a single bitmap and simply offset the top-left screen position, creating a large map would require HUGE amounts of memory.
For a 2-d (inner space type game) keep the start and end of each line and store them in an order that makes identifying off-screen objects easily unrendered (don''t try to display every object for speed''s sake). When displaying objects, draw everything within 50 pixels of the screen coordinates (clipping) into a bitmap then blit the bitmap to screen. The math is fairly simple for 2-d translations. Lookup matrix transformations for the fastest translations and rotations. Overall I''ve found y=mx+b to be the most useful, though.

Good Luck and Have Fun!

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!