Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

problem in C++ - positioning images on screen

I don't really understand how to position the objects in C++... or i got it until my teacher said something and messed everything up.
so, when you're putting an image in the middle of the screen, is it:
object_info.x= screen->w/2;
object_info.y= screen->h/2;
and i also don't get how to access the top, right side, bottom, and left side of the rectangle (of the image)...
thanks

Comments

  • MT2002MT2002 Member Posts: 1,444
    : I don't really understand how to position the objects in C++... or i
    : got it until my teacher said something and messed everything up.
    : so, when you're putting an image in the middle of the screen, is it:
    : object_info.x= screen->w/2;
    : object_info.y= screen->h/2;
    : and i also don't get how to access the top, right side, bottom, and
    : left side of the rectangle (of the image)...
    : thanks
    :
    Useually the program would store the rectangle and render it
    to that location.

    As for position an image on center:
    [code]
    x = (screen_width/2) - (x_pos + obj_width/2)
    y = (screen_height/2) - (y_pos + obj_height/2)
    [/code]

    Graphically (Using the formula for x):
    [code]
    << decrement

    +----------+----------+--screen
    ^ | |
    - | |---|-----------object
    | |---| |
    | ^-| << Here we have to subtract half of the objects
    + | | width from the center
    v +----------+----------+
    | | |
    0 screen_width/2 screen_width
    [/code]

    The same concept applies for the y formula.

    Hope this helps;
Sign In or Register to comment.