1

SFMLとこのチュートリアルを使用して簡単な2Dゲームを作成しようとしています。チュートリアルの現在の進捗状況をコード化する方法は次のとおりです。イベントクラスの列挙型EventTypeに問題があります。メンバー変数名はTypeです。

 #include "stdafx.h"
 #include "SplashScreen.h"


 void SplashScreen::Show(sf::RenderWindow & renderWindow)
 {
    sf::Image image;
    if(image.LoadFromFile("images/SplashScreen.png") != true)
    {
     return;
    }

   sf::Sprite sprite(image);

   renderWindow.Draw(sprite);
   renderWindow.Display();

   sf::Event event;
   while(true)
   {
     while(renderWindow.GetEvent(event))
     {
       if( event.Type == sf::Event::EventType::KeyPressed
         || event.Type == sf::Event::EventType::MouseButtonPressed
         || event.Type == sf::Event::EventType::Closed )
       {
          return;
       }
     }
   }
 }

これは私のstdafx.hです:

 // stdafx.h : include file for standard system include files,
 // or project specific include files that are used frequently, but
 // are changed infrequently
 //

 #ifndef STDAFX_H
 #define STDAFX_H


 #include <stdio.h>


 // TODO: reference additional headers your program requires here
 #include <SFML/System.hpp>
 #include <SFML/Graphics.hpp>
 #include <SFML/Window.hpp>
 #include <SFML/Audio.hpp>

 #include <map>
 #include <iostream>
 #include <cassert>

 #endif //STDAFX_H

イベントの自動補完が機能しているので、Event.hppが含まれているようです。MouseButtonPressedおよび他のすべての列挙値はsf::Event::EventType::、コードブロックのスコープの後に表示されます。Event.hppファイルもチェックしましたが、正しいです。コンパイラが私をいじっている理由がわかりません。

スコープを削除して「event.Type==KeyPressed」とだけ記述しようとすると、コンパイラは「Keypressedはこのスコープで宣言されていません」と表示します。Ubuntu12.04でコードブロック10.05を実行します。

何が悪いのか知っていますか?

編集:これは私のEvent.hppです

4

2 に答える 2

2

The name of the enum is not a scope. Just replace sf::Event::EventType::KeyPressed to sf::Event::KeyPressed.

于 2012-12-15T20:01:11.907 に答える
0

collegue, way you don't include the SF.h directaly ? Like this:

include

////// and use the namespace: using namespace sf;

//// avoiding use sf:: before whole sentence=> //// sf::Event....

while(window.isOpen()) { //.enter code here..

Event event
while(window.pollEvent(event)
{`enter code here`
if(event.type == Event::KeyPressed)
  if(event.key.code == Keyboard::Up)
  `enter code here`
于 2019-10-20T15:17:23.633 に答える