Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Texture drawn at wrong coordinates?

I tried drawing a ‘1’ texture at mouse coordinates when I press the 1 key:

switch (e.type)
{
    case SDL_QUIT:
    {
        quit = true;
        break;
    }
    case SDL_KEYDOWN:
    {
        switch (e.key.keysym.sym)
        {
            case SDLK_1:
            {
                SDL_Rect rect = {e.motion.x - 8, e.motion.y - 8, 16, 16};
                SDL_RenderCopy(gRenderer, gT[3], NULL, &rect);
                printf("1\n");
                break;
            }
        }
        break;
    }
}

I cannot comprehend why this doesn’t work.

gT[3] is the texture of the ‘1’.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I thought maybe it is because its e.key.keysym.sym but I’m not sure.

>Solution :

SDL_Event::motion is only valid when SDL_Event::type is SDL_MOUSEMOTION.

Stop trying to use SDL_Event::motion when SDL_Event::type is SDL_KEYDOWN, perhaps by recording the X and Y coordinates of the most recent SDL_MOUSEMOTION event and using those instead.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading