1
Graphics / Should I re-position a graphical text in the dead center again
« on: July 16, 2022, 12:12:32 pm »
Should I re-position a graphical text in the dead center again, which I previously do, after editing the text of the graphical text, recalculate its new center origin of the text? I did see that with a new origin, the text automatically applied to whatever the previous x and y were. Does it a wasteful thing to add another duplicate line of code to set it in the dead center?
// Draw some text
Text messageText;
// Assign the actual message
messageText.setString("Press Enter to start!");
// Position the text
FloatRect textRect = messageText.getLocalBounds();
messageText.setOrigin(textRect.left +
textRect.width / 2.0f,
textRect.top +
textRect.height / 2.0f);
messageText.setPosition(1920 / 2.0f, 1080 / 2.0f);
/ has the player been squished by a branch?
if (branchPositions[5] == playerSide)
{
// Change the text of the message
messageText.setString("SQUISHED!!");
// Center it on the screen
FloatRect textRect = messageText.getLocalBounds();
messageText.setOrigin(textRect.left +
textRect.width / 2.0f,
textRect.top +
textRect.height / 2.0f);
messageText.setPosition(1920 / 2.0f, 1080 / 2.0f); // Should I add do this line of code?
}
Text messageText;
// Assign the actual message
messageText.setString("Press Enter to start!");
// Position the text
FloatRect textRect = messageText.getLocalBounds();
messageText.setOrigin(textRect.left +
textRect.width / 2.0f,
textRect.top +
textRect.height / 2.0f);
messageText.setPosition(1920 / 2.0f, 1080 / 2.0f);
/ has the player been squished by a branch?
if (branchPositions[5] == playerSide)
{
// Change the text of the message
messageText.setString("SQUISHED!!");
// Center it on the screen
FloatRect textRect = messageText.getLocalBounds();
messageText.setOrigin(textRect.left +
textRect.width / 2.0f,
textRect.top +
textRect.height / 2.0f);
messageText.setPosition(1920 / 2.0f, 1080 / 2.0f); // Should I add do this line of code?
}