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?
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?
What game genre ?
In OpenGL is easy to use "virtual" camera:
glTranslatef(camX, camY, 0); // camera position
glScalef(zoomLevel, zoomLevel, zoomLevel); // zoom
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
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.
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:
No, (10,0) is slightly LEFT. (0,0) in games is top left corner.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
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
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.Code:camX:=player.X-clientwidth/2; camY:=player.Y-clientheight/2; object[n].Draw(object[n].X-camX, object[n].Y-camY);
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.
Last edited by User137; 01-06-2013 at 03:57 AM.
Can anyone recommend a good free Delphi library/SDK for creating scrolling sprite games?
Allegro.pas
Anyway, you should ask that in a new thread.
No signature provided yet.
Bookmarks