VgaGames4 - miscellaneous man-pages

[.. upper level ..]

vg4->misc->bgposition_getbg()

Positioning background-image: calculate position of background-image.

SYNTAX
VG_BOOL vg4->misc->bgposition_getbg(const struct VG_Rect *objrect, struct VG_Position *bgpos, VG_BOOL atonce)

FUNCTION PARAMETERS
objrect Rectangle of the object to be focused
bgpos For returning the position of the background-image
atonce VG_TRUE = focus immediatelly, VG_FALSE = move to object

RETURN VALUE
Returns boolean: - VG_TRUE: Moving - VG_FALSE: Object reached

DESCRIPTION
Positioning background-image: calculate position of background-image. 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. objrect defines the focused object's rectangle on the background-image. According to this bgpos returns the position of the background-image to be drawn onto the window. If atonce is set to VG_FALSE the background-positioning will be done with the velocity given to vg4->misc->bgposition_init().

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

/* 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);

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