@@ -27,6 +27,7 @@ var aspect: float
2727var rootInterface :Control
2828var phase = 0.0
2929
30+ var current_size : Vector2i = Vector2i (1 , 1 )
3031
3132func _ready ():
3233 if (geo != null ):
@@ -38,24 +39,34 @@ func _ready():
3839 if (play_on_start ):
3940 player .load_path (uri );
4041 player .play ();
41- player .audio_init ();
42+
43+ func _process (delta ):
44+ _update_size ();
45+
46+ func _update_size ():
47+ aspect = float (current_size .x ) / float (current_size .y );
48+ var root_size = rootInterface .get_rect ().size
49+ var root_aspect = root_size .x / root_size .y
50+ if current_size == Vector2i (1 , 1 ):
51+ texture_rect .size = Vector2 (root_size .x , root_size .y )
52+ texture_rect .position = Vector2 (0 ,0 )
53+ return
54+ if root_aspect > aspect :
55+ # Fit height
56+ texture_rect .size = Vector2 (root_size .y * aspect , root_size .y )
57+ texture_rect .position = Vector2 ((root_size .x - (root_size .y * aspect )) / 2.0 , 0.0 )
58+ else :
59+ # Fit width
60+ texture_rect .size = Vector2 (root_size .x , root_size .x / aspect )
61+ texture_rect .position = Vector2 (0.0 , (root_size .y - (root_size .x / aspect )) / 2.0 )
4262
4363func texture_update (tex :ImageTexture , size :Vector2i ):
44- aspect = float ( size . x ) / float ( size . y ) ;
64+ current_size = size ;
4565 if (mat != null ):
4666 mat .set_deferred ("shader_parameter/tex" , tex );
4767 if (texture_rect != null ):
4868 texture_rect .set_deferred ("texture" , tex );
49- var root_size = rootInterface .get_rect ().size
50- var root_aspect = root_size .x / root_size .y
51- if root_aspect > aspect :
52- # Fit height
53- texture_rect .size = Vector2 (root_size .y * aspect , root_size .y )
54- texture_rect .position = Vector2 ((root_size .x - (root_size .y * aspect )) / 2.0 , 0.0 )
55- else :
56- # Fit width
57- texture_rect .size = Vector2 (root_size .x , root_size .x / aspect )
58- texture_rect .position = Vector2 (0.0 , (root_size .y - (root_size .x / aspect )) / 2.0 )
69+
5970
6071func audio_update (data :PackedFloat32Array , size :int , channel :int ):
6172 pass
@@ -83,7 +94,6 @@ func load_trigger(p:String):
8394 print ("Loading: " , p )
8495 player .load_path (p );
8596 player .play ();
86- player .audio_init ();
8797
8898func async_load_finish (result ):
8999 print ("Loading result: " , result )
0 commit comments