Am I understanding sprite.flip_h = sign(direction.x) == -1

Does this mean "turn on" Flip H if the following is true? Is this happening because of the sign func or because of the == ? 
  • Nathan Lovato replied

    I think you got it right, but I'm going to rephrase and break it down a bit to ensure that it's as clear as possible.

    The sprite.flip_h variable expects a boolean value: either true or false. We can write sprite.flip_h = true to flip a sprite horizontally and sprite.flip_h = false to un-flip the sprite horizontally and restore its original state.

    The function sign returns a value of -1.0, 0.0, or 1.0 depending on the sign of its argument. We can't directly assign its return value to sprite.flip_h because we need a boolean value.

    Using the two equal signs (==), we create a conditional expression that the computer will evaluate and convert to a value of true or false.

    As a result, the line of code reads like this in plain English: "If the sign of direction.x is equal to -1, flip the sprite horizontally. Otherwise, un-flip it."

    2 loves
  • S
    Sassen888 replied

    Thank you!