Advertisement
Guest User

Basic Drag&Drop

a guest
May 30th, 2016
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. extends KinematicBody2D
  2.  
  3. var Mouse_In = false
  4. var Mpos = get_global_mouse_pos()
  5. var Objectdrag = false
  6. # Mouse_In acts as a check switch for if the mouse has entered the object's hitbox
  7. # Mpos is a simple var to keep check on mouse position, is updated in process
  8. # Objectdrag is an extra var to keep the mouse from dropping the Object if it is still dragging but escapes the objects hitbox
  9.  
  10. func _ready():
  11.     set_fixed_process(true)
  12.  
  13. func _fixed_process(delta):
  14.     Mpos = get_global_mouse_pos()
  15. #Updates the Mpos on Current pos
  16.     if Mouse_In == true:
  17.         if Input.is_mouse_button_pressed(BUTTON_LEFT):
  18.             set_global_pos(Mpos)
  19.             Objectdrag = true
  20.         else:
  21.             Objectdrag = false
  22.  
  23. func _on_KinematicBody2D_mouse_enter():
  24.     Mouse_In = true
  25.  
  26. func _on_KinematicBody2D_mouse_exit():
  27.     if Objectdrag == false:
  28.         Mouse_In = false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement