Hello i was trying to draw a simple square for my game but it is drawing a white square instead of my image. Here is my codes...
paddle.hppclass Paddle
{
public:
Paddle(){}
Paddle(sf::RectangleShape myPaddle);
void Draw(sf::RenderWindow& window);
void setImage();
private:
sf::Texture m_texBackground;
sf::Sprite m_imgBackground;
sf::RectangleShape m_shape;
};
paddle.cppPaddle::Paddle(sf::RectangleShape myPaddle) :m_shape(myPaddle)
{
[b][font=times new roman]setImage();[/font][/b] //This was i talked about
}
void Paddle::setImage()
{
if (!m_texBackground.loadFromFile("img/bats/bat_black.png")) {
std::cout << "bat_black.png didnt open" << std::endl;
}
else {
m_imgBackground.setPosition(m_shape.x, m_shape.y);
m_imgBackground.setTexture(m_texBackground);
//Some scale stuffs
}
}
void Paddle::Draw(sf::RenderWindow& window)
{
window.draw(m_shape);
window.draw(m_imgBackground);
}
game.hpp class Game
{
public:
Game();
void startGame(); //My main while loop here
//some other functions...
private:
sf::RenderWindow m_window;
Paddle m_paddle;
};
game.cppGame::Game()
{
sf::RectangleShape myPaddle(sf::Vector2f(100, 20));
myPaddle.setPosition(sf::Vector2f(m_windowWidth/2.0f, m_windowHeight-4.0f * raketim.getSize().y));
myPaddle.setFillColor(sf::Color::Green);
m_paddle =Raket(myPaddle);
//m_paddle.setImage();
}
void Game::startGame()
{
while (m_window.isOpen())
{
//some other while loops event stuffs functions etc here
m_paddle.Draw(m_window);
//some other functions here
}
}
So i will tell you what is my problem. When i try to call "setImage" function inside from Game.cpp inside of Game constructor all is well, it is working.. i mean drawing the Sprite yes... But when i try to call "setImage" inside from Paddle.cpp inside of Paddle constructor it is drawing a white square... Actually for this paddle thats okay it is drawing at least.. But i added many images for my game walls. it is inside of big loops.. I cant call it from Game constructor always.. So how can i call it from my base class? I checked white box problems but i am already defining my
Texture and my
Sprite in my Paddle.hpp. İ mean it is not disappear inside of small scopes..So whats the problem? Please can you help me? I am asking a question first time..Sorry if i havemistakes