Sprite classes initialize images to them and Player takes a reference to window:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include "Player.h"
Player::Player(sf::RenderWindow &_window): window(_window){
//initialize all sprites belonging to players animation
Sprites plLeft("template_left.png", 1, 6);
void Player::Draw(){
window.draw(plLeft.sprite); //<---THIS WHAT DO I PUT IN HERE TO DRAW A SPRITE!
}
in main, I call the function to draw the sprite with pass by reference
~~~~~
sf::RenderWindow window(sf::VideoMode(800, 600), "BOMBER MAN");
window.setFramerateLimit(30);
Player pl(window);
// run the program as long as the window is open
while (window.isOpen()){
//create an event object
sf::Event event;
//check for events
while (window.pollEvent(event)){
~~~~
}
// clear the window with black colour
window.clear(sf::Color::Black);
//draw sprites
pl.Draw();
// end the current frame
window.display();
}
I want to know why i get this error:
~~error: '((Player*)this)->Player::plLeft' does not have class type|
That's hard to say since you don't provide the relevant definition. The plLeft object in your constructor is local to the constructor and stops existing when the constructor returns. (Assuming it is actually in your constructor -- your code is incomplete and unclear.)
class Player{
public:
Sprites plLeft(std::string, int ,int);
Sprites plRight(std::string, int ,int);
Sprites plUp(std::string, int ,int);
Sprites plDown(std::string, int ,int);
sf::RenderWindow &win;
Player(sf::RenderWindow &_window);
~Player();
nono i seen this mistake so many times yet couldn't understand how it was..., plLeft isnt a function its an object of Sprites, Sprites owns lots of functions that return sprites of type sf::Sprite plus an initialised sprite object.
I can see I have to change some names to communicate better, sorry about that.
Also am trying to minimise the code I give you, used to have a bad habbit of giving people ev-ery-thang.