putting together in Main scene

This commit is contained in:
2020-10-30 15:23:13 +01:00
parent e528d2ec7f
commit edc4b5630d
16 changed files with 433 additions and 188 deletions

View File

@@ -2,25 +2,25 @@ extends AnimatedSprite
enum { RIGHT, DOWN_RIGHT, DOWN, DOWN_LEFT, LEFT, UP_LEFT, UP, UP_RIGHT }
var sprite := UP
export (int) var threshold = 5 # Range to snap around axis direction, in degrees.
export (String, "bus", "police", "car") var skin = "car"
var sprite := UP
var time = 0.0
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
set_animation(skin)
func _process(delta):
"""
The sprite has its own representation of rotation, so we need to tweak things.
The sprite inherits orientation from its parent (track) that must be canceled.
The sprite inherits orientation from its parent (TrackFollow) that must be canceled.
"""
var global = get_global_rotation_degrees()
var local = get_rotation_degrees()
var total = wrapf(global - local, -180.0, 180.0)
var r = snap_rotation(total)
if _update_sprite(r):
print_debug("frame changed")
#print_debug("frame changed")
set_frame(sprite)
# We can just cancel out the "part of" the rotation
# embedded in the sprites, leaving out a small
@@ -28,11 +28,6 @@ func _process(delta):
#set_rotation_degrees(-r)
# ...Or we just cancel out everything
set_rotation_degrees(-total)
get_node("/root/Track2/HBoxContainer/Rotation").set_text("%.1f°" % r)
time += delta
if time >= 0.1:
print_debug("%.1f" % get_rotation_degrees(), "° | global: ", "%.1f" % get_global_rotation_degrees(), "°")
func snap_rotation(r):