2012-03-06 27 views
0

我一直在按照單詞教程單詞,但我得到一個錯誤,我無法得到答案從誰做了教程的人解決!不是'tagINPUT'的成員

我到了教程的這一部分是哪裏出了問題: http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition-Part-6.aspx

我得到的錯誤是:

playerpaddle.cpp(32): error C2039: 'IsKeyDown' : is not a member of 'tagINPUT' 
c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winuser.h(5332) : see  declaration of 'tagINPUT' 

playerpaddle.cpp(36): error C2039: 'IsKeyDown' : is not a member of 'tagINPUT' 
c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winuser.h(5332) : see declaration of 'tagINPUT' 

playerpaddle.cpp(40): error C2039: 'IsKeyDown' : is not a member of 'tagINPUT' 
c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winuser.h(5332) : see declaration of 'tagINPUT' 

1>c:\users\dave\c++\pang\playerpaddle.cpp(54): error C2064: term does not evaluate to a function taking 1 arguments 

有了這個腳本部分:

void PlayerPaddle::Update(float elapsedTime) 
{ 
if(Game::GetInput().IsKeyDown(sf::Key::Left)) 
{ 
    _velocity-=3.0f; 
} 
if(Game::GetInput().IsKeyDown(sf::Key::Right)) 
{ 
    _velocity+=3.0f; 
} 
if(Game::GetInput().IsKeyDown(sf::Key::Down)) 
{ 
    _velocity = 0.0f; 
} 

if(_velocity > _maxVelocity) 
    _velocity = _maxVelocity; 

if(_velocity < -_maxVelocity) 
    _velocity = -_maxVelocity; 

sf::Vector2f pos = this->GetPosition(); 

if(pos.x <= GetSprite().GetSize().x/2 || 
    pos.x >= (Game::SCREEN_WIDTH - GetSprite().GetSize().x/2)) 
{ 
    _velocity = -_velocity; 
} 

GetSprite().Move(_velocity * elapsedTime, 0); 
} 

我附上了我的項目來看看: http://tinyurl.com/7evajju

回答

4

Game中的GetInput()靜態方法返回一個windows結構。很確定這不是你想要的,因爲這個結構只有數據而沒有方法。這個函數實際上並沒有實現,所以如果你「只是讓錯誤消失」,你仍然會對未定義的符號產生鏈接錯誤。

您將其視爲'_tagINPUT'作爲windows typedef如何聲明結構的效果。

你可能打算返回中定義的「輸入」類包括\ SFML \窗口\ Input.hpp

我相信你會通常在SFML窗口類調用GetInput()。

因此,也許你想要的一切都game.h,而不是有:

const sf::Input& GetInput() { return _mainWindow.GetInput(); } 

我想你會做得很好做深專注於C++潛水前的語言轉換成遊戲編程。如果您對遊戲編程感興趣,您可能需要研究能夠讓您製作遊戲的更高級技術。在不投資於理解語言的情況下走下C/C++之路很可能會讓你感到足夠的痛苦,最終你會恨你正在做的事情,這是不幸的。

+0

感謝您的回覆 - 我不明白的是爲什麼這個教程可以工作,但是我的代碼不是這樣的=/ – Sir 2012-03-06 04:52:22

+1

這是關鍵,它們*不是相同的代碼。喬解決了這個問題。最初的代碼是:const static sf :: Input&GetInput();而你的代碼是:const static :: INPUT&GetInput();.輸入和INPUT是兩個完全不同的東西。 – Serapth 2012-03-06 05:14:48

+0

詳細說明,'Input'是用戶定義的類,而'INPUT'是用於保存輸入信息的窗口數據結構。它用在'SendInput'函數中。另外,'INPUT'結構實際上是'_tagINPUT'結構的typedef。 – chris 2012-03-06 05:23:45

相關問題