• Advertisement
Sign in to follow this  

Center or Top Left Corner Coordinates?

This topic is 4334 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm really torn over this... I know it probably doesn't really make any difference, but what's the convention on this? I'm making a 2D top-down space rpg, and I want to know whether I should make the coordinates reference the top left corner or the center of the image.

Share this post


Link to post
Share on other sites
Advertisement
Make it the center; it'll make a lot of things (such as rendering and collision detection) easier.

Share this post


Link to post
Share on other sites
I have Both for rendering.

img.Blit()
img.BlitFromCenter()

But for collision detection, i agree: it's better from the center.

Share this post


Link to post
Share on other sites
Depends how you are doing collision detection. If it is simple rectangular bounding boxes, I find it easier to use top left since a rectangle may not have an exact centre point.

Share this post


Link to post
Share on other sites
Well, it's nothing to do with precision or math or programming. The fact that you put an object's location in the middle of the object is mostly for humans. It's just more intuitive that way, especially if it's a larger object. For instance, if you wanted to center the screen on an object, you should ideally just be able to type

screen.CenterOn(x,y)

and have the object in the center of the screen. If you calculate it based on top-left corners, you have to jump through a few extra hoops just to find the center.

Share this post


Link to post
Share on other sites
Quote:
Original post by EasilyConfused
Depends how you are doing collision detection. If it is simple rectangular bounding boxes, I find it easier to use top left since a rectangle may not have an exact centre point.
@ The OP: Seriously, reference your objects from the center. Almost all aspects of the code (AI, user control, steering, transformations for rendering, and collision detection) will be easier and require fewer workarounds. You can still use bounding boxes; just center them on the object.

To address the above poster's point though, we're using the term 'center' kind of loosely here; it doesn't mean that the bounding volume has to be exactly centered on the object. For example, in a 2D platformer it might make the most sense to have the character referenced from a point between his feet. The point is to make the object reference point whatever is most logical, and that is rarely if ever the upper left corner.

Share this post


Link to post
Share on other sites
Yeah, yeah, I will do it from center. I'm getting some weird stuff that's really creeping me out... why does some of my code reference center as x + width/2 and others as x + width/4? :S

Anyway, I'll just rewrite that, and hopefully I'll find the problem along the way. Thanks again, guys.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement