Is it possible to set PointX and PointY in the center of the sprite automatically, for example at the beginning of the scene. So I could resize sprite from the center.
I thought about something like these:
objects[0].setPointX(objects[0].getCenterX);
but unfortunately there is no setPointX() method
Not really sure what you’re asking here.
Are you asking if there is a way to set Object A to the center position of Object B?
If so, yes, every sprite has a “Center” point, and you’d just use ObjectB.pointX(“Center”) and ObjectB.pointY(“Center”). Use the expression builder the first time you do this, to ensure you get the proper formatting/capitalization/etc.
If you mean something else, you’ll need to provide more detail on what you’re trying to accomplish.
Accordingly to:
http://wiki.compilgames.net/doku.php/gdevelop5/objects/sprite/edit-points
it’s called origin points.
I want to set origin point automatically in the center.
And then use scale tween so the button will scale up from the center not from left to right
You cannot automatically change a point location or modify points at all through events. You will need to modify the origin point in the object properties.
@Silver-Streak I found a workaround:
- At the beginning I set variable of object:
var_X_norm = Object’s X
var_X_big = Object’s X - Object’s width * ((Object’s big scale - Object’s normal scale)/2)
var_X_big - this is where will be the X after it’s scaled
And do the same for Y - Add position animation with the same time as scale animation
to var_X_big and var_Y_big if I want to scale up
and to to var_X_norm and var_Y_norm if I want to scale down
my 2 cents,
i would be more sufficient to actually change the origin points of your sprites.
if there all the same size, and have the origin point at the same spot, this takes seconds to do.
do you use the origin point for something else, or why this approach?
Everywhere I find something is repetitive I try to optimize. At the end it’s faster to code then to manually move all origin points
I saved code as function and I will use this function to different sprites. And moreover I can use this function on different scenes and sprites can be of different sizes
Why can’t you use object.PointX(“Center”) as @Silver-Streak said. It’s already there, why bother reinventing the wheel?
@Silver-Streak said:
You cannot automatically change a point location or modify points at all through events. You will need to modify the origin point in the object properties.
I tried your example but
objects[0].PointX(“Center”);
is not working. I see only black screen. Could you give working example.
Are you trying to use this in a javascript block? If so, I unfortunately cannot help you as I only have info for using it in the event system.
If you are rrying to use it in an event, objects[0] isnt a call that exists.