VgaGames4 - miscellaneous man-pages

[.. upper level ..]

vg4->misc->bgposition_getobj()

Positioning background-image: return window-position of object's background-position.

SYNTAX
struct VG_Position vg4->misc->bgposition_getobj(struct VG_Position objpos)

FUNCTION PARAMETERS
objpos Object's background-position

RETURN VALUE
Returns object's window-position

DESCRIPTION
Positioning background-image: return window-position of object's background-position. A background-image which is greater than the window must be positioned according to an object which shall always be visible, e.g. if the focused object is at the right border of the background-image, the left border of the background-image will not be visible. objpos defines the object's position on the background-image. According to the background-image's position the object's position to be drawn onto the window will be returned. This function must be used for all objects on the background, not only for the focused one.

EXAMPLE
struct VG_Image *bgimg, *objimg;
int bgwidth, bgheight;
struct VG_Rect objrect;
struct VG_Position bgpos, objpos;

/* load background-image and get size */
bgimg = vg4->image->load("background.bmp");
vg4->image->getsize(bgimg, NULL, &bgwidth, &bgheight);

/* initialize background-positioning: velocity 2 pixels, centered rectangle 60% of the window */
vg4->misc->bgposition_init(bgwidth, bgheight, 2, 60);

/* load object and set its rectangle on the background to the left upper corner */
objimg = vg4->image->load("object.bmp");
objrect.x = objrect.y = 0;
vg4->image->getsize(objimg, NULL, &objrect.w, &objrect.h);

/* move background-image to object and draw it onto the window */
vg4->misc->bgposition_getbg(&objrect, &bgpos, VG_FALSE);
vg4->window->copy(bgimg, &bgpos, NULL);

/* get object's window-position and draw it onto the window */
vg4->misc->rect2position(&objpos, &objrect);
objpos = vg4->misc->bgposition_getobj(objpos);
vg4->window->copy(objimg, &objpos, NULL);

SEE ALSO
vg4->misc->bgposition_init() vg4->misc->bgposition_getbg()