C++ Game Development

Moderators: Lundin
Number of threads: 236
Number of posts: 517

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
problem in C++ - positioning images on screen Posted by sparkly_star on 28 May 2007 at 7:29 PM
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
Report
Re: problem in C++ - positioning images on screen Posted by MT2002 on 29 May 2007 at 7:34 PM
: 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:
x = (screen_width/2) - (x_pos + obj_width/2)
y = (screen_height/2) - (y_pos + obj_height/2)


Graphically (Using the formula for x):
<< decrement

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


The same concept applies for the y formula.

Hope this helps;



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.