0

SFML1.6 を使用してグラフィカル アプリ (ゲーム) を作成しています。メインファイル以外にファイルが1つしかないときはうまくいきました。新しいファイル Level を追加すると、次のエラーが発生します。

C:\Users\...\Window.hpp|6|error: 'RenderWindow' in namespace 'sf' does not name a type|
C:\Users\...\Window.hpp|7|error: 'Image' in namespace 'sf' does not name a type|
C:\Users\...\Window.hpp|8|error: 'Sprite' in namespace 'sf' does not name a type|
C:\Users\...\Window.hpp|9|error: 'Color' in namespace 'sf' does not name a type|

正常に動作していたので、新しいファイルが原因だと思います:

レベル.cpp

#include <SFML/Window.hpp>
#include <iostream>

#include "Window.hpp"

class Level
{
     sf::Window* pResultScreen;
     public:
     Level( sf::Window& );
}; 

Level::Level( sf::Window &app)
{
     pResultScreen = &app;
};

レベル.hpp

#ifndef Level_hpp
#define Level_hpp

class Level
{
     sf::Window* pResultScreen;
     public:
     Level( sf::Window& );
};

#endif

上記のコードに問題がある人はいますか?

編集: Window.cpp

class Window
{
sf::RenderWindow appWindow;
sf::Image charImage;
sf::Sprite charSpriteSheet;
sf::Color deleteColor;
bool keyPressed;
int curFrame;
int stateChar;
int timerFrame;
int flipChar;

public:
Window();
int Loop();
void SheetCutter(int); // Prepares tiles
void Animate(int); // Loop through animations
void ColourCleaner(); // Remove the sprite's color.
};

Window::Window()
{
stateChar = 0;
curFrame = 0;
flipChar = 1;

deleteColor.a = 255;
deleteColor.r = 255;
deleteColor.g = 47;
deleteColor.b = 198;

appWindow.Create(sf::VideoMode( 800, 600, 32), "AI_Fighter");
appWindow.SetFramerateLimit(30);

if( !charImage.LoadFromFile("Bass.png") )
{
    std::cout << "Problem opening file 'Bass.png'";
}

charImage.SetSmooth(false);

ColourCleaner();

charSpriteSheet.SetImage(charImage);

SheetCutter(curFrame); // This allows it to not show the entire tile set at the    beginning.
};

int Window::Loop()
{
// Start game loop
while (appWindow.IsOpened())
{
    sf::Event evt;
    while (appWindow.GetEvent(evt))
    {
        // Window closed
        if (evt.Type == sf::Event::Closed)
            appWindow.Close();

        // Escape key pressed
        if ((evt.Type == sf::Event::KeyPressed) && (evt.Key.Code == sf::Key::Escape))
            appWindow.Close();

        if (evt.Type == sf::Event::KeyPressed)
            keyPressed = true;

        else
            keyPressed = false;
    }

    // Get elapsed time
    float ElapsedTime = appWindow.GetFrameTime();

    // Move the sprite
    if ( appWindow.GetInput().IsKeyDown(sf::Key::Left) || appWindow.GetInput().IsKeyDown(sf::Key::Right) || appWindow.GetInput().IsKeyDown(sf::Key::Up) || appWindow.GetInput().IsKeyDown(sf::Key::Down) )
    {
        if (appWindow.GetInput().IsKeyDown(sf::Key::Left))
        {
            charSpriteSheet.Move(-100 * ElapsedTime, 0);
            stateChar = 1;
            flipChar = 0;

            Animate(6);
        }

        if (appWindow.GetInput().IsKeyDown(sf::Key::Right))
        {
            charSpriteSheet.Move( 100 * ElapsedTime, 0);
            stateChar = 1;
            flipChar = 1;

            Animate(6);
        }

        if (appWindow.GetInput().IsKeyDown(sf::Key::Up))
        {
            charSpriteSheet.Move(0, -100 * ElapsedTime);
            stateChar = 2;

            Animate(6);
        }

        if (appWindow.GetInput().IsKeyDown(sf::Key::Down))  charSpriteSheet.Move(0,  100 * ElapsedTime);
    }

    else
    {
        stateChar = 0;

        Animate(12);
    }

    // Clear the screen (fill it with black color)
    appWindow.Clear(sf::Color( 0, 0, 0));

    appWindow.Draw(charSpriteSheet);

    // Display window contents on screen
    appWindow.Display();
}

return 0;
};

void Window::SheetCutter(int offset)
{
charSpriteSheet.SetSubRect(sf::IntRect((offset * 26), 0, ((offset * 26) + 26), 35));
};

// This changes the curFrame, so that animations loop and stuff. Pretty easy, although    unelegant.
void Window::Animate(int rate)
{
charSpriteSheet.FlipX(flipChar);

if((timerFrame%rate) == 0) // This is, rather obviously, a variable designed to allow to change the frames at the right rate.
{
    if(stateChar == 0) // ? Not getting activated. Not getting called...
    {
        if(curFrame >= 2)
        {
            curFrame = 0;
        }

        else
        {
            curFrame++;
        }
    }

    else if(stateChar == 1) // Walking.
    {
        if(curFrame >= 5 || curFrame <= 2 )
        {
            curFrame = 3;
        }

        else
        {
            curFrame++;
        }
    }

    else curFrame = 6; // Jump.

    SheetCutter(curFrame);
}

std::cout << stateChar;
timerFrame++;
};

// This removes the magenta background, changing the colour to tempClr. Color doesn't        really matter as long as the fourth digit is set
// to 0, since it's the alpha value.
void Window::ColourCleaner()
{
sf::Color tempClr(0, 0, 0, 0);

for(int i = 0; i < 182; i++ )
{
    for(int j = 0; j < 35; j++)
    {
        sf::Color CLR = charImage.GetPixel(i, j);
        if(deleteColor == CLR)
        {
            charImage.SetPixel(i, j, tempClr);
        }
    }
}
};

Window.hpp

#ifndef Window_hpp
#define Window_hpp

class Window
{
sf::RenderWindow appWindow;
sf::Image charImage;
sf::Sprite charSpriteSheet;
sf::Color deleteColor;
int curFrame;
int stateChar;
int timerFrame;

public:
Window();
int Loop();
void SheetCutter();
void Animate(int rate);
void ColourCleaner();
};

#endif
4

1 に答える 1

1

#include <SFML/Window.hpp>定義が必要なため、ヘッダー ファイルに を配置する必要があります。(ソース ファイルには、内容を複製する代わりに、ヘッダーを含める必要があります。

于 2012-07-25T10:57:07.733 に答える