–1 vote
if Input.is_key_pressed(KEY_1):
    var Item = get_node("Icon")
    var ItemD = Item.duplicate()
    ItemD.position = get_viewport().get_mouse_position()
    add_child(ItemD)

I am trying to duplicate something on the icon but it appears really off.

Godot version 3.4
in Engine by (13 points)

Have you tried get_global_mouse_position() or checked anchors, margins and offset of the icon?

also You should try applying change to global_position instead of position

They all seem fine and get_global_mouse_position() changed nothing.

same thing happened with global_position

Also you checked Every ancestor nodes' anchors, margins, rect_position, position?

1 Answer

0 votes

Don't You have any code in "Icon" ready() function ?
What do You mean "off" ? Show print screen of that. Perhaps it is just icon is large and its origin point is corner ?

by (5,132 points)

Tried it with a different image and got the same resultI have code that constantly checks for input and if the input is detected it duplicates the sprite.

https://imgur.com/a/l2OooEp

Are there no errors in console ?
Is resulting off-position the same when project is window and fullscreen ?

Same results in fullscreen and no errors in console.

Let's see if this has anything to do with duplication.
Don't duplicate, create icon anew. From Your script I can see this is a Sprite ?

var itemd = Sprite.new()
itemd.global_position = get_mouse_global_position()
add_child(itemd)

This should create icon so its top left corner is at cursor

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.