Author Topic: Shifting the origin of the screen  (Read 937 times)

Offline Bluepixel

  • Mc. Print
  • *
  • Posts: 26
  • www.bluepixel-studios.net
    • View Profile
    • Bluepixel Studios
Shifting the origin of the screen
« on: 2019-Nov-22 »
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)

Offline MrPlow

  • Prof. Inline
  • *****
  • Posts: 1717
    • View Profile
Re: Shifting the origin of the screen
« Reply #1 on: 2019-Nov-22 »
Hi

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

Offline Bluepixel

  • Mc. Print
  • *
  • Posts: 26
  • www.bluepixel-studios.net
    • View Profile
    • Bluepixel Studios
Re: Shifting the origin of the screen
« Reply #2 on: 2019-Nov-22 »
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)

Offline MrPlow

  • Prof. Inline
  • *****
  • Posts: 1717
    • View Profile
Re: Shifting the origin of the screen
« Reply #3 on: 2019-Nov-22 »
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

Offline MrPlow

  • Prof. Inline
  • *****
  • Posts: 1717
    • View Profile
Re: Shifting the origin of the screen
« Reply #4 on: 2019-Nov-22 »
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

Offline Bluepixel

  • Mc. Print
  • *
  • Posts: 26
  • www.bluepixel-studios.net
    • View Profile
    • Bluepixel Studios
Re: Shifting the origin of the screen
« Reply #5 on: 2019-Nov-22 »
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)

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4310
    • View Profile
    • Portfolio
Re: Shifting the origin of the screen
« Reply #6 on: 2019-Nov-23 »
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?

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5064
  • O Rly?
    • View Profile
Re: Shifting the origin of the screen
« Reply #7 on: 2019-Nov-23 »
You have to shift the map not a "Camera" :)
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Bluepixel

  • Mc. Print
  • *
  • Posts: 26
  • www.bluepixel-studios.net
    • View Profile
    • Bluepixel Studios
Re: Shifting the origin of the screen
« Reply #8 on: 2019-Nov-23 »
@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?
« Last Edit: 2019-Nov-23 by Bluepixel »
www.bluepixel-studios.net

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

Offline Bluepixel

  • Mc. Print
  • *
  • Posts: 26
  • www.bluepixel-studios.net
    • View Profile
    • Bluepixel Studios
Re: Shifting the origin of the screen
« Reply #9 on: 2019-Nov-23 »
@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!  :)
« Last Edit: 2019-Nov-23 by Bluepixel »
www.bluepixel-studios.net

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