megamarc / Tilengine

Free 2D graphics engine with raster effects for retro/classic style game development
https://www.tilengine.org
Mozilla Public License 2.0
847 stars 95 forks source link

Input keys of PLAYER1 cannot be changed #52

Closed thacoon closed 5 years ago

thacoon commented 5 years ago

Changing an input key for PLAYER1 is currently not working. I can change INPUT_UP for PLAYER2 to e. But for PLAYER1 the INPUT_UP remains the upper arrow and not the w key.

Example code:

#include <stdio.h>

#include <SDL2/SDL.h>
#include <Tilengine.h>

int main() {
    TLN_Init (400,240, 0,0,0);
    TLN_SetLogLevel(TLN_LOG_VERBOSE);

    TLN_DefineInputKey(PLAYER1, INPUT_UP, SDLK_w);
    TLN_EnableInput(PLAYER1, true);

    TLN_DefineInputKey(PLAYER2, INPUT_UP, SDLK_e);
    TLN_EnableInput(PLAYER2, true);

    TLN_CreateWindow(NULL, 0);

    int frame = 0;

    while(TLN_ProcessWindow()) {
        if(TLN_GetInput(INPUT_P1 + INPUT_UP)) {
            fprintf(stderr, "P1 - INPUT UP is pressed\n");
        }

        if(TLN_GetInput(INPUT_P2 + INPUT_UP)) {
            fprintf(stderr, "P2- INPUT UP is pressed\n");
        }

        TLN_DrawFrame(frame);

        frame++;
    }

    TLN_Deinit();

    return 0;
}
ghost commented 5 years ago

Hi, Use TLN_DefineInputKey after TLN_CreateWindow

megamarc commented 5 years ago

@thacoon : daltomi is right, you must setup keys AFTER creating the window, because the input mapping is part of the windowing subsystem, not the rendering core itself. When the window is created, it sets default bindings for player 1.