Godot Version
4.2.2
My name is Felipe, nice to meet you.
I studied programming 20 years ago, but I only now decided to return and try again due to personal problems. So i decide make a hentai game.
I generally don't ask for help, I prefer to study to understand the subject, but I find myself stuck.
I've been studying Godot for a month and a half, and I've already understood almost the entire program, but the language, despite being easy to understand, is difficult to write. I've been trying to do simple logic for two weeks, but nothing I try works.
The funniest part is that I'm stuck in what I swore would be the easiest part.....
What I'm trying to do is simple: I have a button and when I click it I instantiate an object (which must follow the mouse pointer) and I duplicate it in my scene. In other words, it is a management builder like Black Market or Monster Black Market.
I've tried over 20 different codes but none of them worked....here's the current code:
Contol--
--Button
extends Button
var object_scene: PackedScene = preload("res://scenes/Buildings/build_01.tscn")
var object_to_duplicate: Node2D = null
func _on_pressed():
if object_to_duplicate == null
object_to_duplicate = object_scene.instantiate()
object_to_duplicate.global_position = get_global_mouse_position()
get_tree().root.add_child(object_to_duplicate)
else:
var new_object = object_to_duplicate.duplicate()
new_object.global_position = get_global_mouse_position()
get_tree().root.add_child(new_object)
func _process(delta):
if object_to_duplicate != null:
object_to_duplicate.global_position = get_global_mouse_position()
The problem with this code is:
- The object is created but does not correctly follow the mouse cursor.
- The object is not duplicated on the screen.
If anyone could please help me I would appreciate it....without understanding how this works my project simply ends here.....
Thanks.
4.2.2
My name is Felipe, nice to meet you.
I studied programming 20 years ago, but I only now decided to return and try again due to personal problems. So i decide make a hentai game.
I generally don't ask for help, I prefer to study to understand the subject, but I find myself stuck.
I've been studying Godot for a month and a half, and I've already understood almost the entire program, but the language, despite being easy to understand, is difficult to write. I've been trying to do simple logic for two weeks, but nothing I try works.
The funniest part is that I'm stuck in what I swore would be the easiest part.....
What I'm trying to do is simple: I have a button and when I click it I instantiate an object (which must follow the mouse pointer) and I duplicate it in my scene. In other words, it is a management builder like Black Market or Monster Black Market.
I've tried over 20 different codes but none of them worked....here's the current code:
Contol--
--Button
extends Button
var object_scene: PackedScene = preload("res://scenes/Buildings/build_01.tscn")
var object_to_duplicate: Node2D = null
func _on_pressed():
if object_to_duplicate == null
object_to_duplicate = object_scene.instantiate()
object_to_duplicate.global_position = get_global_mouse_position()
get_tree().root.add_child(object_to_duplicate)
else:
var new_object = object_to_duplicate.duplicate()
new_object.global_position = get_global_mouse_position()
get_tree().root.add_child(new_object)
func _process(delta):
if object_to_duplicate != null:
object_to_duplicate.global_position = get_global_mouse_position()
The problem with this code is:
- The object is created but does not correctly follow the mouse cursor.
- The object is not duplicated on the screen.
If anyone could please help me I would appreciate it....without understanding how this works my project simply ends here.....
Thanks.
Last edited: