Help needed : Creating a 2D Camera View

Posted By: Evo

Help needed : Creating a 2D Camera View - 04/12/20 17:44

I have a 2D game. It uses only panels/images and does not require a 3D level. Because of that, I have no true camera to use and I've had to painfully simulate it. My current version works, but I'd prefer to have an actual 2D view to move around instead. It would allow me to keep the large 2D level pos in place and just move the view around.

* Is there a way to create a 2D view that can show the full level (it's a multi layered panel level) and have a smaller bmap view to pan around it?

* Is there a way to actually create a 2D camera by using a similar method?
Posted By: txesmi

Re: Help needed : Creating a 2D Camera View - 04/12/20 21:48

Hi,
I'm afraid that is only viable on a 3D level where you can place all objects by means of a transformation matrix on the GPU with a low cost.

You might use direct drawing functions and emulate the role of a camera of the engine by checking the bounds of the objects against the bounds of a 2d camera and only draw visible objects. Large levels might need a system that adopts the role of the BSP tree, where the objects are grouped by related areas and the view drawing process only checks the bounds of the objects of the current area and its neighbors instead of the full list of objects. I would avoid using panels. I am afraid the engine checks its visibility each frame. For the case, I think it is better to use structs that are managed by you only. The fastest bounds checks are parallel to screen axes.

Code
for each(obj : currentArea.objList)
   if(intersectBounds(obj, view))
      draw(obj, obj.pos - view.pos + screen_size / 2);
for each(n : currentArea.neighborAreas)
   for each(obj : n.objList)
      if(intersectBounds(obj, view))
         draw(obj, obj.pos - view.pos + screen_size / 2);
Posted By: Evo

Re: Help needed : Creating a 2D Camera View - 04/13/20 12:57

Thanks, Txesmi. That's an interesting idea. With draw functions, I'm sure that a 2D camera could be made that way.

At the moment, I'll have to keep my current method which just simulates 2D camera movement. My current 2D projects (A Top-down JRPG and Retro Platformer) aren't tile-based and they use full image files that are layered to create the levels. So far it works fine, but before I get too far into it, I'll probably consider switching from panels to draw functions.
© 2024 lite-C Forums