Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - datpham2

Pages: [1]
1
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?
}

Pages: [1]