Seems, that altough I made a function for those, it now gives scope errors.
TextureManager.h:
#ifndef TEXTUREMANAGER_H_INCLUDED
#define TEXTUREMANAGER_H_INCLUDED
#include <SFML/Graphics.hpp>
using namespace std;
void loadTextures()
{
sf::Texture texture;
texture.loadFromFile("/data/textures/menu/New Game.pdn");
}
#endif // TEXTUREMANAGER_H_INCLUDED
SpriteManager.h:
#ifndef SPRITEMANAGER_H
#define SPRITEMANAGER_H
#include <SFML/Graphics.hpp>
#include "TextureManager.h"
using namespace std;
void loadSprites()
{
sf::Sprite NewGamesprite(texture);
}
#endif // SPRITEMANAGER_H
main.cpp:
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <iostream>
#include "Character.h"
#include "TextureManager.h"
#include "SpriteManager.h"
using namespace std;
int main()
{
loadTextures();
loadSprites();
sf::RenderWindow window(sf::VideoMode(800, 600), "Reckon Dash.exe", sf::Style::Default);
cout <<"Window open"<<endl;
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
{
window.close();
}
}
window.clear();
window.display();
window.draw(NewGamesprite);
}
return 0;
}
in the loadsprites it says that texture was not declared in this scope and in main.cpp it says that NewGamesprite was not declared in this scope. How to fix??
Please don't keep on this and learn the language, if you knew anything about scopes then you would have no problems, you can't expect to use a C++ library fully without knowing something so basic of the language it's written in. However, given you are still asking and haven't actually read anything like it has been said many times run this:
int main()
{
sf::Texture texture;
texture.loadFromFile("/data/textures/menu/New Game.pdn");
sf::Sprite NewGamesprite(texture);
sf::RenderWindow window(sf::VideoMode(800, 600), "Reckon Dash.exe", sf::Style::Default);
std::cout <<"Window open"<<endl;
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
{
window.close();
}
}
window.clear();
window.draw(NewGamesprite);
window.display();
}
return 0;
}
That should display your sprite, however if you don't learn C++ well you'll just stumble at every single little pebble in your way, if you aren't willing to make an effort then nobody will help you, learn the language first, then use the library as needed. Also try to read a little about the library, that file type may not be supported, use a conventional image type and you'll have no problems.