How to get center point of a image sprite

I have an image sprite (moving and rotation enabled) of dimensions 75 x 55. I want to place another image spirit in the center of the first one. Although I can get coordinates of the top right corner but unable to get that of the center as rotation makes it complicated.
Any extension or mathematical expression will of great help.
Thanks

Let say height is 75 and width is 55

Top is 45 and right is 90,
So divide height and width by 2 to get center point
Now height = 75/2= 38.5
And width = 55/2 = 27.5
For center coordinate add height to top and width to right
Height = 38.5 + 45 = 83.5
Width = 27.5 + 90 = 117.5
I think this helps you

3 Likes

And is SPRITE not SPIRIT.

1 Like

But will it work when the image gets rotated (say 90 degree) as then height and width coordinate will change

Surely it rotates around the centre point so as long as you don’t move it the centre remains the same.

1 Like

Yes, it will still be centered. The rotation is done using the middle of the sprite. Only the positioning and movement (x and y) are the top left corner.

1 Like

dont set height and width in pixels … set it in percentage because different mobiles have different resolutions . you will experience problem due to setting in pixels…use in terms of screen width and height…
another thing… if you have 2 image sprite and if you set its position same… the old sprite (1st image sprite) will hide behind the latest one… so use sprite in this manner, otherwise at last when you notice that you need to work alot … just like me…

@italo @deanart2012 I used this equation before too however it is not giving center position. Please note that image is moving and I am using image.x and image.y function to get it’s position after very small interval of time (40 ms) when object rotates the reference point changes.

Please give me block or code to get the center coordinates of an image sprite in real time.

That’s no big deal. You can change Z coordinates to change their layer. And Image sprite have no % option however I used canvas.width and canvas.height component to make it responsive.

To me this now sounds like:

  1. A mathematical problem , and
  2. A coding problem

You’ll need to do the maths behind it first. Try searching google for your problem. This is something you’ll probably need to do yourself. If someone else on here wants to help then of course they will but you should try yourself first.

Once you have the correct equations put them into blocks. If you can’t do that then post your equations and screenshots of what you have tried and maybe someone can help you.

Why not use heading and speed instead of x,y every 40 ms? It may get better and smoother movement. It will also take care of the rotation problem I guess.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.