# How to center an object in relation to

How to center a modified dynamically object in relation to another.

eg:
-object 1: a square
-object 2: a text that is modified with a variable
-desired result: center modified text in the square

This does not center:

change the position of text = square.X("")-text.Width()/2 (x axis), =square.Y("")-text.Height()/2 (y axis)

An idea?

Is the origin of square/object1 in the centre of the image?

Almost there maybe you need to do

change the position of text = square.X(â€śCenterâ€ť)-text.Width()/2 (x axis), =square.Y(â€śCenterâ€ť)-text.Height()/2 (y axis)

Yes, my image is 64*64
Origin points: X=32 Y=32

Itâ€™s the same result
square.X(â€śCenterâ€ť) is the same than square.X(â€śâ€ť) because my origin points are the centre

I manage to center an initial text to display, but this text is no longer centered when it is dynamically modified with a variable

What do you mean by dynamically modified? As in the text is set to the value of a variable?

If so, do you centre the text after itâ€™s been modified?

1 Like

It works! Problem was I modified variable after changing position.

I created points to an object, points are named â€śtop_leftâ€ť corresponding X=0 Y=0.
How do I write them for a position: square.X("top_left) (x axis), =square.Y(â€śtop_leftâ€ť) (y axis) ?

That should work. The other way (and possibly more correct and/or backwards compatible) is to use square.PointX(â€śtop_leftâ€ť) and square.PointY(â€śtop_leftâ€ť)

both work indeed. I use square.PointX("top_left) and square.PointY("top_left)
thank you!

The result, with each text modified by variables

I still have to make circles have to doâ€¦ Does someone have an idea to do this?

Use a ShapePainter - itâ€™ll handle circles perfectly.

Or use a sprite, if the circles are all the same size.

I used shape painter