Transforming coordinates of one rectangle to another rectangle

前端 未结 3 413
予麋鹿
予麋鹿 2021-01-12 20:29

\"enter

in the above image I have shown two rectangles

  • rectangl
3条回答
  •  一整个雨季
    2021-01-12 21:13

    Try using this:

    rectangelOne.x = rectangelTwo.x + rectangelTwo.width / 2;
    rectangelOne.y = rectangelTwo.y + rectangleTwo.height / 2;
    

    if your rectangleOne's pivot is correctly it should center automatically, otherwhise add this:

    rectangleOne.x -= rectangleOne.width / 2;
    rectangleTwo.y -= rectangleOne.height / 2;
    

    hope this helps.

提交回复
热议问题