#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
#include <sstream>
// Image Variables //
sf::Image * imgTile;
const int tileCount = 2;
// Image Functions //
void loadImages(void)
{
std::stringstream ss;
// Tile Images //
imgTile = new sf::Image[tileCount];
for (int i = 1; i <= tileCount; i++)
{
ss << "\\Content\\Graphics\\Tiles\\" << i << ".png";
imgTile[i].LoadFromFile(ss.str());
ss.str().clear();
}
}
void destroyImages(void)
{
delete [] imgTile; imgTile = NULL;
}
// Main Function //
int main(int argc, char *argv[])
{
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
// Load our images.
loadImages();
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
destroyImages();
App.Close();
}
// Clear the screen (fill it with black color)
App.Clear();
// Display window contents on screen
App.Display();
}
return EXIT_SUCCESS;
}
What is wrong with using static-sized arrays? If you know you have a fixed amount of elements or will not surpass a certain amount, why use vectors? How is that not "the C++ way"?He uses a dynamic array allocated with new[]. There is almost never a reason to prefer it over std::vector, as it is more error-prone, requires manual management and doesn't offer the utilities of STL containers.