how to add a camera to 2d games

BlitzMax Forums/BlitzMax Beginners Area/how to add a camera to 2d games

Twinprogrammer(Posted 2011) [#1]
I was just wondering if you can add a camera in 2d games

Twinprogrammer


GfK(Posted 2011) [#2]
To do what?


ima747(Posted 2011) [#3]
Can you explain what you mean? Presumably a view point that can be moved independent of the world space... if so then yes, by moving everything...

a simple and crude example implementation is to create an x and y offset for the camera, and draw everything relative to the offsets. So rather than drawguy(guy.x, guy.y) you would do drawguy(camera.x + guy.x, camera.y + guy.y).

In the above example you do have to adjust the camera in an inverted fashion, that is to say if you want to move the view point right (increase the viewpoint's x), you have to move the world right (by actually decreasing the viewpoint's x...). You can perform the inversion either when you alter the offset (to move the viewpoint right, you subtract units from it's offset rather than add them...), OR when you reference the offset (use -camera.x instead of camera.x).

Last edited 2011


Twinprogrammer(Posted 2011) [#4]
What's the offset ?

Twinprogrammer


ima747(Posted 2011) [#5]
Camera.x and camera.y in the above example are the offsets.


Twinprogrammer(Posted 2011) [#6]
Do you have any examples possibly ?

Twinprogrammer


Jesse(Posted 2011) [#7]
see if this is any help:
http://www.blitzmax.com/codearcs/codearcs.php?code=2235


Midimaster(Posted 2011) [#8]
did you had a look on my answer to your last question topic?

http://www.blitzbasic.com/Community/posts.php?topic=95393#1101011

this demonstrates, what means "world", "camera" and "offset" and how to scroll.


TomToad(Posted 2011) [#9]
SetOrigin is what you want. no need to offset your drawing at all as SetOrigin will do that for you. I made a nice little tutorial on how it works here: http://www.blitzbasic.com/Community/posts.php?topic=91640