Center or Top Left Corner Coordinates?

Started by
7 comments, last by Riekistyx 18 years ago
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.
Advertisement
Make it the center; it'll make a lot of things (such as rendering and collision detection) easier.
Okay. Will do. Thanks.
I have Both for rendering.

img.Blit()
img.BlitFromCenter()

But for collision detection, i agree: it's better from the center.
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.
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.
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.
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.
make it topleft and make a accessor return the center.

This topic is closed to new replies.

Advertisement