PDA

View Full Version : Scrolling equations?

Darkhog
30-05-2013, 07:19 PM
If I'm not mistaken when making scrolling equation for on-screen object positioning I should use are:

camerax - objectxInScene
cameray - objectyInScene

Am I right?

JC_
31-05-2013, 09:25 AM
What game genre ?

In OpenGL is easy to use "virtual" camera:

glTranslatef(camX, camY, 0); // camera position
glScalef(zoomLevel, zoomLevel, zoomLevel); // zoom

User137
31-05-2013, 11:03 AM
I think the real formula was
objectxInScene - camerax
objectyInScene - cameray

Lets think it through:
Object is in position 100, 100
Camera is in position 90, 100
So we expect that the object will be shown slightly right from camera location. With above formula it becomes
100-90, 100-100 = 10, 0, which is slightly right

pitfiend
01-06-2013, 01:30 AM
I think you need to modify only one axis at a time or your scrolling will be funny. e.g. for scrolling stuff you need to define boundaries, direction and speed, you may have absolute screen boundaries or relative surface boundaries.

Darkhog
01-06-2013, 02:01 AM
Of course I'll scroll one dimension at a time! But since my first project is infinite horizontal shooter, it isn't that important. Just wanted to make sure my equations are right.

Also:

Lets think it through:
Object is in position 100, 100
Camera is in position 90, 100
So we expect that the object will be shown slightly right from camera location. With above formula it becomes
100-90, 100-100 = 10, 0, which is slightly right
No, (10,0) is slightly LEFT. (0,0) in games is top left corner.

User137
01-06-2013, 03:48 AM
10 is to Right from point 0, the axis... When object position X increases, it is going right, yeah? If you want it in the middle of screen, you just have to set the camera coordinates properly. For example focused where player is, it would be cameraPosition = PlayerPosition - ScreenSize/2

camX:=player.X-clientwidth/2;
camY:=player.Y-clientheight/2;
object[n].Draw(object[n].X-camX, object[n].Y-camY);
So if player is at 0, 0, and object would be drawn to 0, 0, it would be in the middle of the screen. Or if player.X is something big 1000, it is natural that object is drawn off the screen far to left.

edit: For horizontal shooter you have it simple, and can set camY is always 0. Although some games such as classic Tyrian allows some horizontal scrolling aswell, being vertical scroller mainly.

alphawiz
09-10-2016, 06:20 PM
Can anyone recommend a good free Delphi library/SDK for creating scrolling sprite games?

Ñuño Martínez
14-10-2016, 05:46 PM
Can anyone recommend a good free Delphi library/SDK for creating scrolling sprite games?

Allegro.pas (http://allegro-pas.sf.net/) 8)

Anyway, you should ask that in a new thread. >:(