Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Ghostly

Pages: [1]
1
Graphics / Problem with image loading with arrays.
« on: August 27, 2012, 02:22:55 am »
Hello, I'm new to using the SFML API, and been using C++ for just a few months, with other graphics APIs, however, I've just started using arrays, and I'm having problems loading my images.

What I want to do is have an array of an specific image type (i.e. tiles) to be able to load them at start-up, and use them at will, by simply using imgTiles[tileimagenum], but I'm stuck at the loading. I keep getting this error at run-time:
http://i.imgur.com/rJzHe.png

And the Autos window, looks like this:
http://i.imgur.com/v1QSQ.png

Here's the code that I'm using:
Code: [Select]
#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;
}

I hope I can get some help on this, and if there's a better way of doing it, please let me know.

Regards,
Ghostly.

Pages: [1]