Making gui node follow cursor on drag without remaining behind (SOLVED)

I am adding multiple gui nodes by code with gui.new_box_node() and I want to drag them on screen. The screen size in config is 640x1136. When the screen is bigger the node remains behind.

    if action_id == hash("touch") then
    		for i = 1, #self.items, 1 do
    			if gui.pick_node(self.items[i], action.x, action.y) then				
    				if action.pressed  then		
    					self.current_item = self.items[i]
    					self.dragging = true
    				elseif action.release then
    					self.current_item = nil
    					self.dragging = false
    				end
    			break
    			end		
    		end
    		if self.current_item and self.dragging then
    			gui.set_position(self.current_item, vmath.vector3(action.x, action.y, 0))
    			return true
    		end 
    end

I am using the default render script with gui_extra_functions (used in another part of the app) and no other modification. I know I have to compensate for the resize, but I am not that clear how. I am getting the window size from the render script.
Thanks.

I don’t see any immediate problems with that snippet of code. Can you share a small example showing the problem you are trying to solve?

As you can see on horizontal the circle does not follow the cursor. It does on vertical because Height < 1136

This is very likely caused by the wrong Adjust Mode on the green circles or possibly a parent. The Adjust Mode decides how a node should be positioned if screen dimensions changes from what you have in game.project. You can read more about adjust modes in the manual:

1 Like

This library could help you with that

3 Likes

@AGulev Thanks, I already use it in my app but I don’t know how to use it in this context.
@britzl I was not setting it from code. Adding Stretch does the trick, but now I don’t have a circle anymore :slight_smile: I am not setting any parent either. Will play with this more.

        local node = gui.new_box_node(vmath.vector3(items[i].position[1], 
                items[i].position[2], items[i].position[3]), 
		vmath.vector3(items[i].size[1], items[i].size[2], items[i].size[3]))
		gui.set_texture(node, "chapter"..self.current_chapter)
		gui.play_flipbook(node, "button_white")
		gui.set_color(node, header_colors[i])
		self.items[#self.items + 1] = node

You should be able to parent it to a node with stretch and maybe move that node instead.

1 Like

Yes this works :sunny: Thank you for all your tutorials, examples and forum support. Makes using this engine a pleasure!

2 Likes