Advertisement

map coordinates?

Started by February 22, 2000 05:02 PM
2 comments, last by ViPeR007 24 years, 6 months ago
I''ve just got scrolling to work and Im trying to figure out how to incorporate a map coordinate system. Like lets say you have a gun''s image being emited from the player and you want that image to be moved around the screen by the maps/world''s coordinates. If you move it by the screen''s coordinates then what happens is when you move, it moves with you instead of moving off the screen in one direction. Does anyone know of a good way to of doing this? Thanx, ViPeR
I think this is the third time I write this anwer here.

Keep all entities in Map coordinates. When drawing you compute the views top left corner''s map coordinates and then draw the entities on the screen at position = UnitPos - ViewPos.
Advertisement
But, can you explain the formula that you have put down? I don''t quite understand how it works.
I''ll give it a try...

All entities positions are given in map coordinates, including the camera/view position.

The algoritm for rendering the map:


  1. Figure out the view''s top left map coordinates. Let''s call this V.
    V is calculated by taking the cameras position and subtracting half of the width and height.
  2. Render the background to the screen. This is done by blitting from the map a rectangle going from V to (V.x + Width, V.y + Height).
  3. For every entity in the world.

    • Compute the entities screen coordinates. Let''s call this E.
      You do this by taking the entities map coordinates and subtracting V.
    • Check if E is within the screen. If its not it shouldn''t be rendered.
    • Render the entity by blitting its surface to the screen with destination rectangle (E.x, E.y, E.x+Entity width, E.y+Entity height)

  4. Move all entities according to their logic.
  5. Start over from the beginning.


I hope that helps

This topic is closed to new replies.

Advertisement