Advertisement
metalx1000

Godot 360 Car Spinner

May 29th, 2021
4,418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends AnimatedSprite
  2. var drag_enabled = false
  3. var drag_value = 0
  4. var mouse_pos = 0
  5. var mouse_current = 0
  6. var current_frame = 0
  7.  
  8. onready var number_frames = get_sprite_frames().get_frame_count("default");
  9.  
  10. func _process(delta):
  11.     if drag_enabled:
  12.         mouse_current = get_global_mouse_position();
  13.         drag_value = mouse_pos.x - mouse_current.x;
  14.         if drag_value > 0:
  15.             current_frame += 1;
  16.         if drag_value < 0:
  17.             current_frame -= 1;
  18.            
  19.         if current_frame > number_frames:
  20.             current_frame = 0;
  21.         elif current_frame < 0:
  22.             current_frame = number_frames;
  23.        
  24.         set_frame(current_frame);
  25.         mouse_pos = get_global_mouse_position();
  26.        
  27. func _input(event):
  28.     if event is InputEventMouseButton:
  29.         if event.button_index == BUTTON_LEFT:
  30.             if event.pressed:
  31.                 drag_enabled = true;
  32.                 mouse_pos = get_global_mouse_position();
  33.             else:
  34.                 drag_enabled = false;
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement