Skip to content

Commit 5a0e98b

Browse files
committed
added GetMousePosition node
1 parent 8431e60 commit 5a0e98b

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
tool
2+
extends VisualScriptCustomNode
3+
4+
func _get_caption():
5+
return "Get Mouse Position"
6+
7+
func _get_category():
8+
return "Input"
9+
10+
func _get_text():
11+
return ""
12+
13+
func _get_input_value_port_count():
14+
return 1
15+
16+
func _get_input_value_port_name(idx):
17+
return "Base"
18+
19+
func _get_input_value_port_type(idx):
20+
return TYPE_OBJECT
21+
22+
func _get_output_value_port_count():
23+
return 1
24+
25+
func _get_output_value_port_name(idx):
26+
return "position"
27+
28+
func _get_output_value_port_type(idx):
29+
return TYPE_VECTOR2
30+
31+
func _step(inputs, outputs, start_mode, working_mem):
32+
if not inputs[0] or !inputs[0] is CanvasItem:
33+
return "Object isn't of type CanvasItem"
34+
outputs[0] = inputs[0].get_viewport().get_mouse_position()
35+
return 0

addons/vs_custom_nodes/addvsnodes.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const globalvar = preload("res://addons/vs_custom_nodes/AccessGlobalVariable.gd"
88
const topdown2d = preload("res://addons/vs_custom_nodes/TopDownController2D.gd")
99
const loaddir = preload("res://addons/vs_custom_nodes/LoadDirectory.gd")
1010
const twodimiterator = preload("res://addons/vs_custom_nodes/2DIterator.gd")
11+
const getmousepos = preload("res://addons/vs_custom_nodes/GetMousePosition.gd")
1112

1213
func _enter_tree():
1314
# add the custom node to the Visual Script Editor on start-up
@@ -17,6 +18,7 @@ func _enter_tree():
1718
VisualScriptEditor.add_custom_node("TopDownController2D", "Controller", topdown2d)
1819
VisualScriptEditor.add_custom_node("LoadDirectory", "Input", loaddir)
1920
VisualScriptEditor.add_custom_node("2DIterator", "Math", twodimiterator)
21+
VisualScriptEditor.add_custom_node("GetMousePosition", "Input", getmousepos)
2022
# the add_custom_node() takes the "name" and "category" as index that will be used to later remove the node
2123

2224
func _exit_tree():
@@ -27,3 +29,4 @@ func _exit_tree():
2729
VisualScriptEditor.remove_custom_node("TopDownController2D", "Controller")
2830
VisualScriptEditor.remove_custom_node("LoadDirectory", "Input")
2931
VisualScriptEditor.remove_custom_node("2DIterator", "Math")
32+
VisualScriptEditor.remove_custom_node("GetMousePosition", "Input")

0 commit comments

Comments
 (0)