2013-07-13 52 views
-1

我在查找用於將Xbox 360編碼到我的項目中的示例或教程。到目前爲止,我一直只使用SDL_keysym來使用箭頭鍵和WASD鍵來移動我的精靈。想知道我如何整合Xbox 360(最好)或遊戲杆支持。如何將Joystick支持或Xbox 360支持集成到SDL中

下面是我目前使用箭頭和WASD鍵移動我的精靈Spaceship1的代碼。因爲代碼混亂,請原諒我。

struct oSprite 
{ 
int m_nTotalFrames; 
int m_nCurrentFrame; 
int m_nFrameWidth; 
int m_nFrameHeight; 

fVector2 m_vPosition; 

SDL_Surface* m_pImage; 

bool  m_bIsHuman; 
oControls m_oControls; 
oControls m_oAltControls; 
}; 

bool Update() 
{ 
fVector2 vKeyPresses; 

Uint8* paunKeyStates = SDL_GetKeyState(NULL); 
float fMoveSpeed = 0.5f; 

if(paunKeyStates[g_Spaceship1.m_oControls.m_nUpButton] || paunKeyStates[g_Spaceship1.m_oAltControls.m_nUpButton]) 
{ 
    vKeyPresses.y -= fMoveSpeed; 
} 

if(paunKeyStates[g_Spaceship1.m_oControls.m_nDownButton] || paunKeyStates[g_Spaceship1.m_oAltControls.m_nDownButton]) 
{ 
    vKeyPresses.y += fMoveSpeed; 
} 

if(paunKeyStates[g_Spaceship1.m_oControls.m_nLeftButton] || paunKeyStates[g_Spaceship1.m_oAltControls.m_nLeftButton]) 
{ 
    vKeyPresses.x -= fMoveSpeed; 
} 

if(paunKeyStates[g_Spaceship1.m_oControls.m_nRightButton] || paunKeyStates[g_Spaceship1.m_oAltControls.m_nRightButton]) 
{ 
    vKeyPresses.x += fMoveSpeed; 
} 
} 

回答

0

在日SDL的初始化試試這個

SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK)