1
General / Loading the Image in a class?
« on: October 18, 2008, 10:34:09 pm »
Hi!
I am trying a bit with dynamic Image loading but i can't get it to work:
The screen turns up like this:
The proportions are right of the image but it won't show the actual picture.
I am running the SVN version of SFML, built on Mac OSX 10.5.5
I am trying a bit with dynamic Image loading but i can't get it to work:
Code: [Select]
#include "KillPillar.h"
#include "libs.h"
using namespace std;
class Pillar {
private:
//Pillarinfo
int number;
string name;
int layer;
//SRPITELOADING
vector<sf::Sprite> sprites;
vector<sf::Image> images;
vector<string> names;
public:
bool loadsprite (string filename, string name) {
sf::Image Image;
if (!Image.LoadFromFile(filename)) {
return 0;
}
images.push_back(Image);
sf::Sprite Sprite(Image);
sprites.push_back(Sprite);
names.push_back(name);
return 1;
}
sf::Sprite & fetchSprite (string name) {
for(int i = 0; i <= sprites.size(); i++) {
if(name == names[i]) {
return sprites[i];
}
}
}
};
int main() {
sf::RenderWindow App(sf::VideoMode(1024, 768), "PILLAR KILLER EXTREME");
const sf::Input& Input = App.GetInput();
Pillar forsta;
if(!forsta.loadsprite("pillar.png", "start")) {
return EXIT_FAILURE;
}
while (App.IsOpened())
{
bool LeftKeyDown = Input.IsKeyDown(sf::Key::Left);
bool RightKeyDown = Input.IsKeyDown(sf::Key::Right);
bool UpKeyDown = Input.IsKeyDown(sf::Key::Up);
bool DownKeyDown = Input.IsKeyDown(sf::Key::Down);
bool EnterKeyDown = Input.IsKeyDown(sf::Key::Return);
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
if(RightKeyDown) {
forsta.fetchSprite("start").Move(2,0);
}
// Clear screen
App.Clear();
// Draw the sprite
App.Draw(forsta.fetchSprite("start"));
// Update the window
App.Display();
}
return EXIT_SUCCESS;
}
The screen turns up like this:
The proportions are right of the image but it won't show the actual picture.
I am running the SVN version of SFML, built on Mac OSX 10.5.5