Skip to content

Mouse Click Question plus Two features request [startDrag & stopDrag node] #363

Closed

Description

@BracerJack

Image

Question 3: Can we, like Flash, have a startDrag and StopDrag node? In case you might be worrying it is "extra node", for consistency sake you already have the stop and play sound wrapper node which makes it really easy to play sound.

Currently in Godot, this is the amount of Drama you need just to click and drag a node:
`
This is how the draggable object is to be setup.
Area2D
└AnimatedSprite2D [or Sprite2D]
└CollisionShape2D [inside it contains RectangleShape2D]

Create a script for the Area2D node, connect its input_event~ signal to it.

Enter these in:
extends Area2D

var selected:bool = false
var mouse_offset:Vector2 = Vector2(0,0)

func _process(delta: float) -> void:
if selected:
followMouse()

func followMouse() -> void:
position = get_global_mouse_position() + mouse_offset

func _on_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
if event.is_pressed():
mouse_offset = position - get_global_mouse_position()
#If you are using touch and are getting major positional offset error/bug:
#In the Project Settings, uncheck "Emulate Mouse From Touch", this should fix it, don't do anything else.
selected = true
else:
selected = false
`

In Flash, all one have to do is:
on (pressed)
{startDrag();}

That's like...two lines of code....19 years ago, somewhere along the line complexity = cool?

Yap, startDrag() and stopDrag(), that's it, who would have thought it could have been that simple ;p
Can we have a startDrag and stopDrag node for both 2D and 3D objects in Block Code? The kids are going to love this simplicity because it could have been this simple, it was done 19 years ago!
Can this sanity be restored to Godot using Block Code?

Thanks.
25 Jan 2025

Activity

  1. changed the title [-]Mouse Click Question plus Two features request[/-] [+]Mouse Click Question plus Two features request [startDrag & stopDrag node][/+] on Jan 25, 2025
  2. locked and limited conversation to collaborators on Jan 30, 2025
  3. converted this issue into a discussion #372 on Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions