Can someone explain me why is my code is outputitng an white rectangle instead of the properly texture?
Sorry for my bad english btw
main.cpp:
#include <SFML/Graphics.hpp>
#include <vector>
#include <iostream>
#include "Player.h"
int main(){
sf::RenderWindow janela(sf::VideoMode(512, 512), "titulo", sf::Style::Default);
sf::Texture texture, tex1, tex2, tex3, tex4;
texture.loadFromFile("Idle (1).png");
tex1.loadFromFile("Idle (2).png");
tex2.loadFromFile("Idle (3).png");
tex3.loadFromFile("Idle (4).png");
tex4.loadFromFile("Idle (5).png");
std::vector<sf::Texture> texturas;
texturas.push_back(texture);texturas.push_back(tex1);texturas.push_back(tex2);texturas.push_back(tex3);texturas.push_back(tex4);
Player jogador(texturas);
//jogador.corpo.setTexture(texture);
sf::Clock clock;
sf::Time tempo;
while(janela.isOpen()){
sf::Event e;
while(janela.pollEvent(e)){
if(e.type == sf::Event::Closed){
janela.close();}
}
tempo = clock.getElapsedTime();
if(tempo.asSeconds() <=20){
std::cout<<tempo.asSeconds()<<std::endl;
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){
jogador.corpo.move(0.1f,0);
std::cout<<jogador.corpo.getPosition().x;
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){
jogador.corpo.move(-0.1f,0);
std::cout<<jogador.corpo.getPosition().x;
}
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)){
jogador.corpo.setPosition(sf::Mouse::getPosition(janela).x,sf::Mouse::getPosition(janela).y);
}
janela.clear(sf::Color(150, 150, 150));
janela.draw(jogador.corpo);
janela.display();
}
return 0;
}
Player.h
#ifndef PLAYER_H
#define PLAYER_H
#include <SFML/Graphics.hpp>
class Player{
public:
Player(std::vector<sf::Texture> texturas);
~Player();
sf::Sprite corpo;
void Anim();
private:
};
#endif /* end of include guard: */
Player.cpp:
#include "Player.h"
Player::Player(std::vector<sf::Texture> texturas)
{
corpo.setTexture(texturas[0]);
corpo.setPosition(20.f, 20.f);
corpo.setOrigin(250,250);
corpo.setScale(0.1f,0.1f);
}
Player::~Player()
{
}
void Player::Anim(){
}
Also i tried using pointers in the textures but i dont think i used it correctly