I'm trying to implement constructors and inheritence in my program. In previous version, everything was running ok, but now i can't draw my sprite (player1.playerS). I dont know where problem or problems are lying.
Here are files of my program:
sfml001.cpp:
#include <SFML/Graphics.hpp>
#include "events.h"
#include "player.h"
using namespace sf;
int main()
{
VideoMode VMode(1280, 720, 32);
RenderWindow window( VMode, "Game");
Player player1;
window.setFramerateLimit(120);
while(window.isOpen()){ //zwraca w petli while informacje, czy okno aplikacji jest otwarte
EventsInProgram event1(window, player1.plRectSourceSprite);
window.clear(Color(0, 110, 0));
window.draw(player1.playerS);
window.display();
}
return 0;
}
player.cpp
#include <SFML/Graphics.hpp>
#include "player.h"
#include <string>
using namespace sf;
using namespace std;
Player::Player(VideoMode VM , IntRect plRectSourceSprite){//, string tex){
VMode = VM;
Texture playerT;
playerT.loadFromFile("heroanimation.png");
Sprite playerS(playerT, plRectSourceSprite);
}
player.h
#pragma once
#include <SFML/Graphics.hpp>
#include <string>
using namespace sf;
using namespace std;
class Player{
public:
Sprite playerSprite;
IntRect playerRectSourceSprite;
IntRect plRectSourceSprite;
Texture playerT;
VideoMode VMode;
Clock playerMoveClock;
Clock playerAnimationClock;
Sprite playerS;
Vector2f playerSpeedVector;
Vector2f playerPosition;
int playerSpeed = 300;
//int playerLives = 1;
private:
public:
Player(VideoMode VM = {1280, 720, 32}, IntRect plRectSourceSprite = {0, 0, 60, 60});//, string tex ="heroanimation.png");//, Texture tex );
~Player();
};
events.cpp
#include <SFML/Graphics.hpp>
#include "events.h"
#include "player.h"
using namespace sf;
EventsInProgram::EventsInProgram(RenderWindow & window, IntRect playerRectSourceSprite){
eventList(window, playerRectSourceSprite);
}
EventsInProgram::~EventsInProgram(){}
void EventsInProgram::eventList(RenderWindow & window, IntRect playerRectSourceSprite){//, Event & zdarzenie){
Event zdarzenie;
bool pause01 = 0;
while( window.pollEvent( zdarzenie ) ){
if( zdarzenie.type == Event::Closed ){
window.close();
}
if(Keyboard::isKeyPressed(Keyboard::Escape)){
if(pause01 = 0) pause01 = 1;
else if(pause01 = 1) pause01 = 0;
}
if(zdarzenie.type == Event::KeyReleased) playerRectSourceSprite.top = 0;
}
}
events.h
#pragma once
#include <SFML/Graphics.hpp>
#include "player.h"
using namespace sf;
class EventsInProgram {
public:
EventsInProgram(RenderWindow & window, IntRect playerRectSourceSprite);
~EventsInProgram();
void eventList(RenderWindow & window, IntRect playerRectSourceSprite);
};