1
Window / Texture error?
« on: March 15, 2024, 04:37:48 am »
Hello. I have a mini game that is similar to pang and I managed to get everything working well. I tried to make a menu system so when you die/win it won't simply close the window and you have to open it again, and it will instead go to the main menu and restart everything. So, when restarting everything I stumbled upon a problem with the balls when activating them.
When you activate a ball via starting a game (activate 1 ball), or shooting at an already existing ball (it will activate 2 balls), it will change the texture of the ball to another one with a texture of a smaller ball.
When in the first iteration of the game, every ball will have their texture initialized for the first time, giving no issue, but when in the second+ iteration, it will start having issues when trying to reapply a new texture.
There are no errors or anything but some of the textures are really messed up and it wouldn't look good to make a game like this.
When you activate a ball via starting a game (activate 1 ball), or shooting at an already existing ball (it will activate 2 balls), it will change the texture of the ball to another one with a texture of a smaller ball.
When in the first iteration of the game, every ball will have their texture initialized for the first time, giving no issue, but when in the second+ iteration, it will start having issues when trying to reapply a new texture.
There are no errors or anything but some of the textures are really messed up and it wouldn't look good to make a game like this.
void Ball::init(const int ballSize, const bool active)
{
m_ballSize = ballSize;
m_ballWidth = m_ballSizes.sizeX[m_ballSize];
m_ballHeight = m_ballSizes.sizeY[m_ballSize];
m_ball.setSize(sf::Vector2f(m_ballWidth, m_ballHeight));
m_ballTexture.loadFromFile(m_ballSizes.fileNames[m_ballSize]);
m_ball.setTexture(&m_ballTexture);
m_hitPointX = m_ballSizes.hitPointX[m_ballSize];
m_hitPointY = m_ballSizes.hitPointY[m_ballSize];
if(!active)
{
deactivate();
}
}
This is the function that activates a new ball
{
m_ballSize = ballSize;
m_ballWidth = m_ballSizes.sizeX[m_ballSize];
m_ballHeight = m_ballSizes.sizeY[m_ballSize];
m_ball.setSize(sf::Vector2f(m_ballWidth, m_ballHeight));
m_ballTexture.loadFromFile(m_ballSizes.fileNames[m_ballSize]);
m_ball.setTexture(&m_ballTexture);
m_hitPointX = m_ballSizes.hitPointX[m_ballSize];
m_hitPointY = m_ballSizes.hitPointY[m_ballSize];
if(!active)
{
deactivate();
}
}