Allright I'm trying to draw a character sprite from a sprite sheet (3 wide, 4 deep), only drawing IntRect(32,0,32,32) specifically for now, just want some valid output. To quickly describe my current setup this is what I have...
main.cpp Supposed to do the standard stuff. Build a render window, basic initialization and some simple event checking, then just clearing to grey and drawing the object's sprite.
#include <SFML/Graphics.hpp>
#include <iostream>
#include "creature.hpp"
#define screenWidth 800
#define screenHeight 600
int main ( void )
{
// ############################### VARIABLE DECLARATION ############################### //
// Window creation
sf::VideoMode vMode(screenWidth, screenHeight, 32);
sf::RenderWindow App (vMode,"Test");
App.setFramerateLimit(60);
App.setVerticalSyncEnabled(true);
std::cout << "App Initialized" << std::endl;
// Texture loading / Sprite Creation
sf::Texture playerSheet;
if (!playerSheet.loadFromFile("player.png"))
return EXIT_FAILURE;
// Create creature object
creature player(playerSheet,sf::IntRect(32,0,32,32));
// ############################### GAME LOOP ############################### //
while (App.isOpen())
{
// ############################### EVENTS ############################### //
sf::Event event;
while (App.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
App.close();
break;
case sf::Event::KeyPressed:
switch (event.key.code)
{
case sf::Keyboard::Escape:
App.close();
break;
}
break;
}
}
// ############################### DRAW ############################### //#
App.clear(sf::Color(125,125,125));
player.draw(App);
App.display();
}
}
creature.hpp Now as for the object's draw function:
#pragma once // Avoid multiple includes
#include <SFML/Graphics.hpp>
class creature
{
public:
creature(sf::Texture tex, sf::IntRect zone); // Constructor
~creature(void); // Destructor
void draw (sf::RenderWindow& App);
private:
// Visual
sf::Sprite creatureSpr;
};
creature.cpp I've cropped away unecessary crap from both these files since they're not even implemented yet, just a bunch of declared variables which are set to default values and not really used for now. But as you can see it's designed to be constructed with a texture and a specified zone, which is applied in the constructor, and then displayed by reference using the draw function of the app passed by reference.
#include "creature.hpp"
creature::creature(sf::Texture tex, sf::IntRect zone)
{
// Set texture and zone
creatureSpr.setTexture(tex);
creatureSpr.setTextureRect(zone);
}
void creature::draw (sf::RenderWindow& App)
{
App.draw(creatureSpr);
}
creature::~creature(void)
{
}
Output results in an empty 32*32 white opaque rectangle. Leads me to believe the creatureSpr.setTexture() is failing for some reason, however the setTextureRect appears to work... what's going on? :O