I have a header file that has a function. That loads my sprites since I have 35 of the same. However, I need to draw the sprites in my main file. Or, If there is a better way to do this?
How would I return my 35 sprites to my main file?
Code
Pathfind.h
#pragma once
#include<iostream>
#include<cmath>
//Sfml Includes
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
void createMap(int) {
int rowNumber = 1;
sf::Texture mapSprites;
int map[35] = { 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 };
int tileNumber = 1;
if (!mapSprites.loadFromFile("LevelSprites.png")) {
std::cout << "mapSprites not Loading" << std::endl;
} //For loading the sprites.
std::vector<sf::Sprite> sprites(35, sf::Sprite(mapSprites));
for(tileNumber = 0; tileNumber < 35; tileNumber++) {
if (map[tileNumber] == 0){
for (int i = 0; i < sprites.size(); i++) {
sprites[i].setTextureRect(sf::IntRect(0, 0, 60, 60)); //First panel
sprites[i].setPosition( (tileNumber % 7 + 1) * 60, rowNumber * 60);
sprites[i].setScale(2, 2);
}
}//end if statement
if (tileNumber % 7 == 0)
rowNumber++;
}//ends for statement
}
Main code
#include<iostream>
#include <cstdlib> //Random No
#include <ctime> //Time
//Sfml Includes
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include"Pathfind.h"
int main() {
std::cout << "Swords of Alleria Start" << std::endl;
sf::RenderWindow window(sf::VideoMode(840, 600), "Swords of Alleria");
sf::Event CloseCheck;
window.setFramerateLimit(60);
sf::Font font;
createMap(0);
if (!font.loadFromFile("corbel.ttf")) {
std::cout << "Error: Font not found." << std::endl;
}
else {
std::cout << "Font corble Loaded" << std::endl;
}
//Random Seed
srand(time(NULL));
while (window.isOpen())
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Return)) {
}
while (window.pollEvent(CloseCheck))
{
if (CloseCheck.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color::Black);
//I need to draw them here
window.display();
}
return 0;
}
thanks in advance.