Shifting the origin of the screen

Previous topic - Next topic

Bluepixel

Hi there, i am working on a small game that uses a camera, i got some nice movement down however i havent got the camera working yet, i could just move everything but the player, however i thought that instead i could be moving the origin of the screen, which is normally at the top left of the screen. is there a function or library for this? Or will i have to think of something else myself?
www.bluepixel-studios.net

There are two ways to write error-free programs; only the third one works.
(Alan J. Perlis)

MrPlow

Hi

You could look into Viewport - quite useful for that kind of thing.
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

Bluepixel

Hi there, how exactly do I use a viewport for cameras, I have messed around with viewports and I am still quite confused as to of how they work.
www.bluepixel-studios.net

There are two ways to write error-free programs; only the third one works.
(Alan J. Perlis)

MrPlow

also you can use a CREATESCREEN to create the playarea and shift the coords with the player movement - (especially if you have HUD info around the play area.



Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

MrPlow

Also, if you are using a tile-based screen map system that logic applies where you can decrement and increment the x and y offsets and include the function to only draw tiles x-far and y-far from the player's central position.

I did a similar thing for my WIP Roguelike

Lots of ways but depending on the type of game and the elements, one way might be better than the other.
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

Bluepixel

Hi there, thanks for all of your replies, however I have not been able to use viewports to create a 2d camera, I'm not quite sure how its possible to use viewports for something like that since as far as I'm aware its just picture in picture rendering or am I wrong? I have tried messing around with it however I cant get it to show offscreen sprites which is what I need for making a camera  :doubt:

If you know how I can use viewports or createscreen to make a 2d camera then I would love to, however I'm not sure how.

My take on a 2d camera is that maybe if you shift the origin of the screen you can simulate a camera, is there a function for this?

But either way, thanks a lot for your help so far  =D
www.bluepixel-studios.net

There are two ways to write error-free programs; only the third one works.
(Alan J. Perlis)

erico

Mr.plow´s replies seems to cover everything as far as I can think about it.
I personally use the virtual screen for that but it truly depends on the game type.

This game here is sidescroller and tile based, it uses a virtual screen as I account for stuff just outside the play area.


What is your game supposed to be?

Schranz0r

You have to shift the map not a "Camera" :)
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Bluepixel

#8
@Schranz0r
Hi there, this was my original take on simulating a camera, however if you can shift the origin of the screen you can do just that :) Is there a function for this? Or will i have to write something myself?
www.bluepixel-studios.net

There are two ways to write error-free programs; only the third one works.
(Alan J. Perlis)

Bluepixel

#9
@MrPlow
Hi there, i am creating a small top down multiplayer game that uses networking, which is why i dont feel like virtual screens do the trick  :doubt:
Not just that but i might also want to add some zooming for the camera aswell.

Viewports are indeed usefull of camera controls however, i dont feel like its exactly what im looking for, also because i might implement an endless map, and since viewports cant have a negative width and height, i dont think the map can be infinite when you use viewports.

This is why i think its better to shift everything but the player, or better yet, move the player and shift the origin of the screen.
However when it comes to platformers, Viewports are the way to go! Thanks a lot for showing me this function  :good:

Anyways, about shifting the origin of the screen, maybe i should post a feature request for this since this can be extremely usefull. And i have also decided to maybe write a couple  functions to simulate this.  =D

Either way, thanks a lot for your help!  :)
www.bluepixel-studios.net

There are two ways to write error-free programs; only the third one works.
(Alan J. Perlis)