Camera Variables

int xwin, ywin;
int cameratracking, cameratracker;

xwin, ywin - The position of the camera in pixels.

cameratracking - Alters behaviour of the camera. (See below)

cameratracker - An entity index for the camera to follow, even if this entity isn't the player. (See below)

The camera variables are used to control where on the map the screen is looking. By default cameratracking is set to 1, which means the screen will follow the current player entity around as they move. The xwin and ywin hold the top left corner of the screen position in map (x, y) pixel coordinates, and will update to keep the player in the center of the screen on each Render().

Setting cameratracking to 0 turns off this behavior, so you can manually set the xwin and ywin values, and verge will abide by them.

Setting cameratracking to 2 makes the camera follow the target of the cameratracker instead, a reference to a valid entity index which you want the camera to follow.


Post a new comment?

Talkback #1 written by Zip on 2004-06-28.

void ChangePlayer(int chpl_player)

// Changes the current player with a smooth camera transition
// Pass: The entity index to become the new player
// Sets old coords to current top left screen x,y
int chpl_oldx = xwin;
int chpl_oldy = ywin;
// Sets new coords to centered on the player-to-be
int chpl_newx = entity.x[chpl_player] - (screenx/2) + 8;
int chpl_newy = entity.y[chpl_player] - (screeny/2) + 8;
cameratracking = 0; // Disconnects the camera from the player
int chpl_time = timer; // Records current time
// Loops until half a second has past (adjust as needed)
while ((timer - chpl_time) < 50)
// Sets the coords to point along line over time
xwin = (chpl_oldx + ((timer - chpl_time) * (chpl_newx - chpl_oldx) / 50));
ywin = (chpl_oldy + ((timer - chpl_time) * (chpl_newy - chpl_oldy) / 50));
Render(); // Renders the map
ShowPage(); // Blits the buffer to the screen
SetPlayer(chpl_player); // Sets the new player
cameratracking = 1; // Reconnects the camera to the player

Function for creating a smooth camera pan when changing players. Useful for any map based battle system where the control frequently passes from one entity to another. Depending on circumstances of use, you may want to add in SetEntitiesPaused(1) at the beginning then (0) at the end, or have speed adjusted by distance.


[Edit: Slightly prettier code... g'dam < problems]

Post a new comment?

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford. is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.