Klasa Przeszkoda trzyma informacje na temat bloczkow, ktore potem beda wyswietlone na ekranie. Zawiera statyczny obiekt sf::Image by kazdy klocek nie wczytywał własnego obrazka
Program sie kompiluje, ale włączając debugera wyswietla nastepujacy komunikat:
Child process PID: 3156
Program received signal SIGSEGV, Segmentation fault.
In sf::Sprite::SetImage () (D:\buda\Projekt\Projekt v01\bin\Debug\sfml-graphics.dll)
At D:\buda\Projekt\Projekt v01\Przeszkoda.cpp:22
klasa Przeszkoda:
plik
Przeszkoda.h
#ifndef PRZESZKODA_H
#define PRZESZKODA_H
#include <SFML/Graphics.hpp>
class Przeszkoda
{
static sf::Image kostki;
sf::Sprite textura;
public:
int x,y;
//Przeszkoda();
//virtual ~Przeszkoda();
static void WczytajGrafike(sf::Image i)
{
kostki=i;
}
void Ustaw(int x, int y, int typ);
void DrawKostka(sf::RenderWindow * app);
protected:
private:
};
#endif // PRZESZKODA_H
plik Przeszkoda.cpp
#include "include/Przeszkoda.h"
#include <SFML/Graphics.hpp>
sf::Image Przeszkoda::kostki;
void Przeszkoda::Ustaw(int x, int y, int typ)
{
if(typ==1)
textura.SetSubRect(sf::IntRect(0,0,16,16));
this->x=x;
this->y=y;
textura.SetImage(kostki);
textura.SetPosition(x,y);
}
void Przeszkoda::DrawKostka(sf::RenderWindow * app)
{
app->Draw(textura);
}
W main wczytuje obrazek by potem ustawic statyczny Image:
sf::Image Image;
if (!Image.LoadFromFile("bloczki.png"))
return EXIT_FAILURE;
Przeszkoda::WczytajGrafike(Image);