Jump to content

View more

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

SDL Input Manager

4: Adsense

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   

167
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?

 

 



#2 ApochPiQ   Moderators   

22538
Like
0Likes
Like

Posted 15 August 2013 - 11:17 AM

Please do not cross-post.
Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]




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.