SFML community forums

Help => Graphics => Topic started by: sammynammy on September 17, 2008, 06:36:57 pm

Title: [solved] white sprite
Post by: sammynammy on September 17, 2008, 06:36:57 pm
hi everyone,

i want to draw a sprite on my screen but i just get a white rectangle.

this is my code:
Glider.h
Code: [Select]

#ifndef GLIDER_H
#define GLIDER_H

#include <SFML/Graphics.hpp>
#include "Entity.h"
//------------------------------------------------------------
class CGlider : public CEntity
{
public:
CGlider();
CGlider(const float fX, const float fY);
virtual ~CGlider();

void Initialize();
void Uninitialize();
void Draw();
void Idle(float flDeltaTime);

private:
sf::Sprite m_pSprite;
};
#endif

Glider.cpp
Code: [Select]

#include "Glider.h"
#include "core/KeyboardManager.h"
#include "Game/GameManager.h"
//-----------------------------------------------------------
extern sf::RenderWindow App;
//-----------------------------------------------------------
void CGlider::Initialize()
{
sf::Image Resource;
if(!Resource.LoadFromFile("C:/...Resourcen/Gleiter/gleiter.bmp"))
GAMEMANAGER->QuitWithError("Datei Resourcen/Gleiter/gleiter.bmp nicht gefunden");
m_pSprite.SetImage(Resource);
}
//-----------------------------------------------------------
void CGlider::Draw()
{
App.Draw(m_pSprite);
}
//-----------------------------------------------------------



this is a tutorial for coding an 2D-game.
by using the debug instruments of the VS2008 i found out that after loading the bmp-file the pixel array of the Resource object is completely white, Color(0,0,0,255) and its also displayed in white. but i just dont get my mistake.
perhabs you could help me...
Title: [solved] white sprite
Post by: Wizzard on September 17, 2008, 07:10:48 pm
Resource is deleted before the sprite is drawn.
Try making Resource member data.