gpt4 book ai didi

c++ - 不是 'tagINPUT' 的成员

转载 作者:行者123 更新时间:2023-11-27 23:25:52 25 4
gpt4 key购买 nike

我一直在逐字逐句地学习教程,但我收到一个错误,我无法从制作教程的人那里得到答案!

我到达了教程的这一部分,这是错误的地方: 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

最佳答案

Game 中的 GetInput() 静态返回一个窗口结构。很确定这不是您想要的,因为该结构只有数据而没有方法。这个函数实际上并没有实现,所以如果你“只是让错误消失”,你仍然会遇到 undefined symbol 的链接器错误。

您将其视为“_tagINPUT”,这是 Windows typedef 声明结构的方式的结果。

您可能打算返回 include\SFML\Window\Input.hpp 中定义的“输入”类

我相信您通常会在 SFML 窗口类上调用 GetInput()。

所以也许你想要的只是 game.h 而不是:

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

我认为在深入研究游戏编程之前,您最好先将 C++ 作为一门语言来学习。如果您只对游戏编程感兴趣,那么您可能想要研究能让您制作游戏的更高层次的技术。在不了解语言的情况下走 C/C++ 道路很可能会给您带来足够的痛苦,以至于您最终会讨厌您正在做的事情,这将是不幸的。

关于c++ - 不是 'tagINPUT' 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9577917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com