How to get gui node position with anchor

How I can get screen position of gui node that is anchored top. I tried gui.get_screen_position but its not working .

It is not working how? What is the value you get and what is the expected value?

1 Like

I want to get coin position of score node which is children of topbar node anchored with top and topbar children of root node.

Could it be related to pivot not taken into account when calculating screen position?

1 Like

Ok, getting node position is now solved.

But I wanted to create coins after enemy destroyed and animate those coins to score node. So Coins are created using new_box_node but when deleting node I am getting error node deleted. If I have to do coins tweens animation to score node how I can do that.

Can you please show the exact error message and the code for this?

Here is the code for creating and animating coins node

 elseif message_id == hash("spawn_coin") then
            self.coin = gui.new_box_node(message.position, vmath.vector3(60,60,0))
            gui.set_parent(self.coin, gui.get_node("score"), true)
            gui.set_texture(self.coin, "main")
            gui.play_flipbook(self.coin, hash("Coins"))
            gui.animate(self.coin, "position", vmath.vector3(22,0,0), gui.EASING_LINEAR, 3, 0, on_animation_done, gui.PLAYBACK_ONCE_FORWARD)

and here it is deleting node after animation done

local function on_animation_done(self)
    -- print(self.coin)


ERROR:SCRIPT: /game/gui/HUD.gui_script:110: Deleted node
stack traceback:
[C]:-1: in function delete_node
/game/gui/HUD.gui_script:110: in function </game/gui/HUD.gui_script:109>

When you say “coins”, I suspect that you send multiple events “spawn_coin”.
Yet, you only keep track of a single coin with “self.coin”.

So, if you spawn two coins, before the first coin is done animating, the second coin will be deleted twice! (Since you overwrite the “self.coin”)

I think it should be enough if you instead use “local coin = gui.new_box_node()” etc. since these coins have a short lifespan and aren’t really used for anything else (if I’m not mistaken).