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!

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 .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.