How to center an object in relation to

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

-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 :+1: