VgaGames4

VgaGames4 - input man-pages

[.. upper level ..]

# vg4->input->update()

Retrieve input-events.

SYNTAX
VG_BOOL vg4->input->update(VG_BOOL needsfocus)
FUNCTION PARAMETERS

needsfocus | Whether to suspend game if it is not focused

RETURN VALUE
Returns boolean: - VG_TRUE: OK - VG_FALSE: Got exit-request
DESCRIPTION
Retrieve input-events. This function should be called once per game-loop, to retrieve the input-events from keyboard, gamecontrollers and mouse since last call. The return value VG_FALSE indicates that the user wants to close the window. Therefore the game should exit.
EXAMPLE

    /* a game-loop just waiting for pressing "Q" */

    int key_quit;

    if (!VG_init("test")) { exit(1); }
    if (!vg4->window->open(VG_WINDOW_SIZE_LOW, VG_WINDOW_SCALE_NONE)) { VG_dest(); exit(1); }

    /* set Quit-key to keyboard "Q" */
    if ((key_quit = vg4->input->key_insert("Quit", VG_FALSE, VG_FALSE)) == 0) { VG_dest(); exit(1); }
    vg4->input->key_setkbd(key_quit, VG_INPUT_KBDCODE_Q);

    /* game-loop: do nothing as waiting for Q-key */
    for (;;) {
      if (!vg4->input->update(VG_TRUE)) { VG_dest(); exit(0); }

      if (vg4->input->key_newpressed(key_quit)) { break; }

      vg4->misc->wait_time(50);
    }

    printf("Q pressed\n");

    VG_dest();
    exit(0);

SEE ALSO
vg4->nw->update()