I have started making my first game( a pong game )with ruby (Gosu). I'm trying to detect the collision of two images using their location by comparing the location of the object (a ball) to another one(a player).

For example:

if  (@player.x - @ball.x).abs <=184 && (@player.y - @ball.y).abs <= 40
            @ball.vx = -@ball.vx
            @ball.vy = -@ball.vy

But my problem is that with these numbers, the ball collides near the player sometimes, even though the dimensions of the player are correct.

So my question is from where does the x values start to count? Is it from the center of gravity of the image or from the beginning of the image? (i.e When you add the image on a specific x,y,z what are these values compared to the image?


1 Answer 1


The origin is in the top left corner.

  • The x, y coordinate are from the top left corner of the screen to the top left corner of your image.
    x: horizontal and y: vertical.
  • The z coordinate changes the order of display, the images with a higher z position will be drawn over those with a lower one (source)

enter image description here


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .