Witam,
Od kilku dni siedzę i szukam błędu w swoim kodzie. Jest to póki co szkielet prostej gry. Na potrzeby szukania błędy wyłączyłem zbędne klasy, które zajmowały się menu itp. Zostawiłem tylko sam problem.
Kod się kompiluje i odpala. W main() mam w teraz tylko jedną klasę "player1" i próbę narysowania jej w oknie.
Klasa Player dziedziczy po sf::Drawable i sf::Transformable. Jeśli przeklejam kod z kontruktora do main() - to obiekt się normalnie rysuje. Zakładam więc, że spartoliłem coś z dziedziczeniem i klasa Player.. ale nie mam pojęcia już co.
main()
#include <SFML/Graphics.hpp>
#include <iostream>
#include "Game.h"
#include "Player.h"
#include "Engine.h"
int main()
{
unsigned int screenwidht = 1280;
unsigned int screenheight = 960;
sf::RenderWindow window(sf::VideoMode(screenwidht, screenheight), "Andzia Je Ciastko!", sf::Style::Titlebar | sf::Style::Close);
//Game Gra;
Player player1;
//Engine machine;
while (window.isOpen())
{
sf::Event akcjaOkna;
while (window.pollEvent(akcjaOkna))
{
switch (akcjaOkna.type)
case sf::Event::Closed:
window.close();
break;
}
// Gra.runGame(window);
// if (Gra.state==1)
// {
window.clear();
window.draw(player1);
window.display();
// }
}
return 0;
}
Player.h
#ifndef PLAYER_H
#define PLAYER_H
#include <SFML/Graphics.hpp>
#include <iostream>
class Player :public sf::Drawable,
sf::Transformable
{
private:
sf::Texture texture;
sf::Sprite sprite;
void draw(sf::RenderTarget &target,sf::RenderStates states) const;
public:
Player();
~Player();
};
#endif // PLAYER_H
Player.cpp
#include "Player.h"
Player::Player()
{
texture.loadFromFile("textures/andziaplayer.png");
sf::Sprite sprite (texture, sf::IntRect (0, 0, 160, 360));
}
Player::~Player()
{
std::cout<<"aaaaaaaaa";
}
void Player::draw(sf::RenderTarget & target, sf::RenderStates states) const
{
target.draw(sprite, states);
}
z góry dziękuję za sugestie