Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


SDL Input Manager


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • This topic is locked This topic is locked
1 reply to this topic

#1 Agreon   Members   -  Reputation: 161

Like
0Likes
Like

Posted 15 August 2013 - 10:19 AM

Hy,

I worked on an Input manager but it doesnt work.

This is, what it looks like:
 

#include "cInput.h"


cInput::cInput(void)
{
    m_MouseX = 0;
    m_MouseY = 0;

    for(int i = 0; i < 323; i++)
    {
        m_keys[i] = false;
    }
}

void cInput::handleInput(SDL_Event evt)
{
    while(SDL_PollEvent(&evt))
    {
        switch(evt.type)
        {
        case SDL_QUIT:
            running = false;
            break;
        case SDL_KEYDOWN:
            m_keys[evt.key.keysym.sym] = true;
            //if i add if(evt.key.keysym.sym == SDLK_ESACPE) running = false; it works.
            break;
        case SDL_KEYUP:
            m_keys[evt.key.keysym.sym] = false;
            break;
        case SDL_MOUSEBUTTONDOWN:
            if(evt.button.button == SDL_BUTTON_LEFT)
            {
                m_leftMouse = true;
            }
            else
            {
                m_rightMouse = true;
            }
            m_MouseX = evt.button.x;
            m_MouseY = evt.button.y;
            break;
        case SDL_MOUSEBUTTONUP:
            if(evt.button.button == SDL_BUTTON_LEFT)
            {
                m_leftMouse = false;
            }
            else
            {
                m_rightMouse = false;
            }
            m_MouseX = evt.button.x;
            m_MouseY = evt.button.y;
            break;
        case SDL_MOUSEMOTION:
            m_MouseX = evt.button.x;
            m_MouseY = evt.button.y;
            break;
        }
    }
}


bool cInput::keyPressed(SDLKey key) // Here is the function
{
    return m_keys[key];
}

bool cInput::leftMousePressed()
{
    return m_leftMouse;
}


bool cInput::rightMousePressed()
{
    return m_rightMouse;
}


int cInput::getMousePositionX()
{
    return m_MouseX;
}


int cInput::getMousePositionY()
{
    return m_MouseY;
}

But now, when i try to use it in my main update function, it doesnt work. The Function "keyPressed" returns false every time.
 

if(Input->keyPressed(SDLK_ESCAPE))
{
    running = false;
}

 

Does anybody have an Idea what im doing wrong?

 

 



Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 16079

Like
0Likes
Like

Posted 15 August 2013 - 11:17 AM

Please do not cross-post.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS