# How can I finely controll the position of a node?

**URL:** <https://forum.defold.com/t/how-can-i-finely-controll-the-position-of-a-node/46884>\
**Category:** Questions\
**Created:** [March 20, 2019, 4:04pm UTC](https://forum.defold.com/t/how-can-i-finely-controll-the-position-of-a-node/46884 "2019-03-20T16:04:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jerakin](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jerakin/32/3997_2.png) [@Jerakin](https://forum.defold.com/u/Jerakin)\
**Post date:** [March 20, 2019, 4:04pm UTC](https://forum.defold.com/t/how-can-i-finely-controll-the-position-of-a-node/46884/1 "2019-03-20T16:04:10Z")

</div>

My screen got a button that I want to keep in the same position regardless of how the screen scales.

 ![00](https://forum-defold.b-cdn.net/uploads/default/original/2X/e/e2210cb662be2cf3d5c12d0a129d258e3956efcb.png)

If I use X Anchor and Y Anchor on it it moves (because it is 10% from the right).

 ![26](https://forum-defold.b-cdn.net/uploads/default/original/2X/0/06839ed837ae98e9ca7dd256f15b2bf503b99a9b.png) ![21](https://forum-defold.b-cdn.net/uploads/default/original/2X/8/8656ec7aa752a0d5b5c243a840611d008d0a90bd.png)

I could create a parent node set it at the width of the screen and use X Anchor on that. But that only solved the X (and gives me an extra node which is bad in GUI heavy scenes, because you could hypothetically run out). How can I make it in the correct place in Y?

Here is the project.  
[AdjustmentMode.zip](https://forum.defold.com/uploads/default/original/2X/5/50a598e2070424bb30877b6c16e4f42417d391d2.zip) (1.2 MB)

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [March 20, 2019, 9:57pm UTC](https://forum.defold.com/t/how-can-i-finely-controll-the-position-of-a-node/46884/2 "2019-03-20T21:57:43Z")

</div>

> [@Jerakin](#):
>
> How can I make it in the correct place in Y?

I don’t know how to solve it without one more node.  
But if we will add one more node with the next options, it will work:

 ![image](https://forum-defold.b-cdn.net/uploads/default/original/2X/2/2f388ac76448ffe4dafa74d7cbb9a40717015759.png)  
Project:  
[AdjustmentMode.zip](https://forum.defold.com/uploads/default/original/2X/c/c7839fd939814fe6b544c359af85ac86f2f9c3c2.zip) (1.4 MB)

What the logic:  
`inv_panel` is Stretch node, that mean that his node has dynamic size depends on resolution.  
What is the anchor point in case when size could be changed? Top right corner of this panel (because our button position should be static relative to this corner).  
That means that we need to add a point in top right corner that will be pinned there (or respect the same rules, as a panel node)  
That why I added this `respect_parent` node in this corner.  
Last thing here: set position of our button inside this new node (we have to turn off anchors for this button)

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [March 20, 2019, 10:02pm UTC](https://forum.defold.com/t/how-can-i-finely-controll-the-position-of-a-node/46884/3 "2019-03-20T22:02:14Z")

</div>

Also it possible to use this way:

 ![image](https://forum-defold.b-cdn.net/uploads/default/original/2X/c/ca61f2c402b05ad28d214ed214b09f7cb953665c.png)  
(it works because our `respect_parent` node uses the same mode as `inv_panel`, that means this point will be all the time in the same place.)

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [March 20, 2019, 10:10pm UTC](https://forum.defold.com/t/how-can-i-finely-controll-the-position-of-a-node/46884/4 "2019-03-20T22:10:10Z")

</div>

Technically, it’s possible to do without parent node, but then you need a bigger texture for the button.

 ![image](https://forum-defold.b-cdn.net/uploads/default/original/2X/6/6233f5ac0cbb5aa42907b0d92583aaa328f7f2bf.jpeg)  
or…  
Defold needs more flexible pivot point system with vector3 pivot point (that applies negative pivots too) instead of “side of the world” system. But, unfortunately, for now, it’s out of our near future plans, as I know. @britzl knows more

---

<div class="post-metadata">

**Author:** ![Jerakin](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jerakin/32/3997_2.png) [@Jerakin](https://forum.defold.com/u/Jerakin)\
**Post date:** [April 24, 2019, 10:00am UTC](https://forum.defold.com/t/how-can-i-finely-controll-the-position-of-a-node/46884/5 "2019-04-24T10:00:47Z")

</div>

Got another questions about Adjustment modes and anchoring 🙂

I have a fairly complex scene, which I want to scale in a certain way. But I just can’t figure out a way to do it. Is it possible to do with Adjustment modes and Anchoring? Or do I need to do it manually in code?

 ![question](https://forum-defold.b-cdn.net/uploads/default/original/2X/d/db73e305176b7a0e260b8a63982a1824ffd5bfa4.png)

My problem is that I can’t get the pink box to stay in a decent relative position to the grey one.

Any ideas?

Here is a test project  
[layoutTesting.zip](https://forum.defold.com/uploads/default/original/2X/6/690209d980e5cc173b6ed088353c8837c157590b.zip) (5.0 MB)

---

<div class="post-metadata">

**Author:** ![Jerakin](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jerakin/32/3997_2.png) [@Jerakin](https://forum.defold.com/u/Jerakin)\
**Post date:** [April 27, 2019, 10:46am UTC](https://forum.defold.com/t/how-can-i-finely-controll-the-position-of-a-node/46884/6 "2019-04-27T10:46:10Z")

</div>

Would really appreciate if you could take a look at this when you have the time @AGulev or @britzl or anyone 🙂

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [April 27, 2019, 2:01pm UTC](https://forum.defold.com/t/how-can-i-finely-controll-the-position-of-a-node/46884/7 "2019-04-27T14:01:49Z")

</div>

In this case, you wanna use “fit” for the position and “stretch” for size and I don’t know how to do that ( (maybe @britzl know?)  
I have only one idea: to use “fit” for your scroll list for the position and calculate/set the size of the stencil node manually.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [April 28, 2019, 6:47am UTC](https://forum.defold.com/t/how-can-i-finely-controll-the-position-of-a-node/46884/8 "2019-04-28T06:47:07Z")

</div>

> [@AGulev](#):
>
> In this case, you wanna use “fit” for the position and “stretch” for size and I don’t know how to do that ( (maybe @britzl know?)

I’d need to experiment with that. I can try to squeeze that in next week, but I’m pretty pressed for time right now.

---

<div class="post-metadata">

**Author:** ![Jerakin](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jerakin/32/3997_2.png) [@Jerakin](https://forum.defold.com/u/Jerakin)\
**Post date:** [May 5, 2019, 7:34pm UTC](https://forum.defold.com/t/how-can-i-finely-controll-the-position-of-a-node/46884/9 "2019-05-05T19:34:35Z")

</div>

So I figured I should just change the size of the box myself - but I am having some problems with the math. Do anyone know how I should do it?

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [May 15, 2019, 7:14am UTC](https://forum.defold.com/t/how-can-i-finely-controll-the-position-of-a-node/46884/10 "2019-05-15T07:14:40Z")

</div>

> [@Jerakin](#):
>
> So I figured I should just change the size of the box myself - but I am having some problems with the math. Do anyone know how I should do it?

Sure!  
[Archive.zip](https://forum.defold.com/uploads/default/original/2X/f/fd7a969c97e558dc6a9e826d80132739987aac87.zip) (6.5 KB)

```lua
	local stencil_node = gui.get_node("stencil")
	local layout_size = vmath.vector3(720, 1280, 0) -- your layout size
	local screen_size = vmath.vector3(570, 1155, 0) -- Hardcoded for simplicity, but it should be: (render.get_window_width(), render.get_window_height(), 0)

	local sx, sy = screen_size.x / layout_size.x, screen_size.y / layout_size.y -- scale coef for x and y
	local fit = math.min(sx, sy) --a fit scale coefficient 
	local node_size = gui.get_size(stencil_node) -- get current size
	node_size.y = node_size.y/fit * (1/sy) -- when we divide by fit we canceling a fit transformation and then apply a stretch by multiplying (1/sy)
	gui.set_size(stencil_node, node_size)

```

---

<div class="post-metadata">

**Author:** ![Jerakin](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jerakin/32/3997_2.png) [@Jerakin](https://forum.defold.com/u/Jerakin)\
**Post date:** [May 15, 2019, 9:34am UTC](https://forum.defold.com/t/how-can-i-finely-controll-the-position-of-a-node/46884/11 "2019-05-15T09:34:49Z")

</div>

Thank you @AGulev works like a charm!
