Advertisement
Guest User

Untitled

a guest
May 30th, 2016
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. extends KinematicBody2D
  2.  
  3. var Mpos = get_global_mouse_pos()
  4. var LMB_ON = false
  5. #Mpos is Mouse Postion
  6. #LMB_ON is Left Mouse Button is pressed, I decided to do a var so I can check it in Procces(Delta) then call it to use anywhere else.
  7.  
  8. func _ready():
  9.     set_process(true)
  10.     set_process_input(true)
  11.  
  12. func _process(delta):
  13.     Mpos = get_global_mouse_pos()
  14. #Updates the Mpos on Current pos
  15.     if Input.is_mouse_button_pressed(BUTTON_LEFT):
  16.         LMB_ON = true
  17.     else:
  18.         LMB_ON = false
  19. #checks if Left Mouse Button is Pressed, if is turn var LMB_ON and then off when done.
  20.    
  21.     #print (Mpos)
  22.     #print (LMB_ON)
  23. # A few Printers to check if the vars are working
  24.  
  25. func _on_KinematicBody2D_mouse_enter():
  26. #useing a node connection to check for mouse in the area of the sprite
  27.     print ("touched")
  28.     if LMB_ON == true:
  29.         print ("pressed")
  30.         self.set_pos(Mpos)
  31. #now if the mouse is in the area and the LMB is on then it should keep itself attached to the Mpos.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement