0

Hello! I am learning SDL on lazy foo site! I have a problem with this code what does it mean? what is the "/2" stand for?

apply_surface( ( SCREEN_WIDTH - message->w ) / 2, ( SCREEN_HEIGHT - message->h ) / 2, message, screen );

Please help!

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Kanoisa
0

Hi, Im no expert on SDL,... but just reading that line of code im fairly sure what the code is doing,... but not so sure as to what the result will be.

apply_surface( ( SCREEN_WIDTH - message->w ) / 2, ( SCREEN_HEIGHT - message->h ) / 2, message, screen );

//break this down 
  ( SCREEN_WIDTH - message->w ) / 2
  // SCREEN_WIDTH is the with of the screen(drawing canvas) you are using. its taking from that the width of the message its going to show and dividing the result by 2.

  ( SCREEN_HEIGHT - message->h ) / 2
  // this is doing the same but with th height .

My guess is that either this is going to center a message about the origin (hence the divide by 2 to get half the width as half goes on either side)

or it wants to know the border area around the message if it was centered for whatever reason.

But like i say im no SDL expert but that to me is what it is doing .

Edited by Kanoisa: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.