类中的函数:一个被看到,但另一个被忽略

时间:2016-08-17 16:09:14

标签: c++ sfml

我目前正在使用SFML和C ++开发一款小游戏,但我遇到了问题。我在character.h中有一个类字符,里面有2个函数,但是当我尝试在另一个文件(Game.cpp)中访问这些函数时,一个完美地工作,而另一个就像它甚至不存在一样。由于这是我的第一篇文章,而且我不知道如何正确展示我的代码,所以请告诉我,如果我不够清楚。 感谢大家,祝你有个美好的一天。

错误讯息: enter image description here

/****CHARACTER.H****/
#ifndef CHARACTER_H
#define CHARACTER_H
#include <SFML/Graphics.hpp>

using namespace std;

class Character{

public:
    Character();
    ~Character();
    void initPlayer(string& fileName, sf::IntRect rect);
    void moveCharacter();
    sf::Sprite m_sprite;

private:
    sf::VertexArray m_vertices;
    sf::Texture m_texture;

};

#endif





/****CHARACTER.CPP*****/
#include "/home/hichem/C++/sfml/Game Engine/character.h"
#include "string"
#include <iostream>

using namespace std;

Character::Character(){


}

Character::~Character(){

}

void Character::initPlayer(string& fileName, sf::IntRect rect){
    if (!m_texture.loadFromFile(fileName, rect)){
        cout << "failed to load image" << endl;
    }
    m_sprite.setTexture(m_texture);
    m_sprite.setPosition(sf::Vector2f(400, 200));
 }

void Character::moveCharacter(){

}



/****GAME.H****/
#ifndef GAME_H
#define GAME_H
#include <SFML/Graphics.hpp>
#include "character.h"
#include "tileMap.h"
#include "string"

class Game: public sf::Transformable{
    public:
        Game();
        ~Game();
        void run(sf::RenderWindow &window);


    private:
        void event(sf::RenderWindow &window);
        void update();
        void draw(sf::RenderWindow &window);
        TileMap carte;
        Character player;
        const int level_1[128] =
        {
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        };

};

#endif // GAME_H



/****GAME.CPP****/
#include "Game.h"

using namespace std;
Game::Game(){
    string a = "images/tiles.png";
    carte.load(a, sf::Vector2u(50, 50), level_1, 16, 8);
    string b = "images/player.png";

    /*FUNCTION THAT WORKS FROM CHARACTER.H*/
    player.initPlayer(b, sf::IntRect(0,0,50,50));
}

Game::~Game(){
    //dtor
}

void Game::event(sf::RenderWindow &window){
    sf::Event event;
    while (window.pollEvent(event)){
        if (event.type == sf::Event::Closed)
            window.close();
        /*FUNCTION THAT DOES NOT WORKS FROM CHARACTER.H*/
        player.moveCharacter();
    }
}

void Game::update(){

}

void Game::draw(sf::RenderWindow &window){
    window.clear();
    window.draw(carte);
    window.draw(player.m_sprite);
    window.display();
}

void Game::run(sf::RenderWindow &window){
    while(window.isOpen()){
        event(window);
        update();
        draw(window);
    }
}

1 个答案:

答案 0 :(得分:0)

感谢你的帮助!昨晚我真的很累,并没有注意到我在character.cpp中链接了错误的路径