@@ -7,9 +7,7 @@ import flixel.util.FlxColor;
77import flixel .util .FlxTimer ;
88import haxe .io .Path ;
99import sys .FileSystem ;
10-
11- import hxcodec .flixel .FlxVideo ;
12-
10+ import hxcodec .flixel .FlxVideoSprite ;
1311
1412class AttractState extends FlxState
1513{
@@ -20,9 +18,8 @@ class AttractState extends FlxState
2018 var pressAnyText : FlxText ;
2119 var demoTimer : Float = 0 ;
2220 var pressAnyTimer : Float = 0 ;
23-
24- var player : FlxVideo ;
2521
22+ var videoSprite : FlxVideoSprite ;
2623
2724 override public function create (): Void
2825 {
@@ -32,50 +29,43 @@ class AttractState extends FlxState
3229 label = new FlxText (0 , 0 , FlxG .width , " " );
3330 label .setFormat (null , 24 , FlxColor .WHITE , " center" );
3431 label .y = FlxG .height - 40 ;
35- add (label );
36-
37- // DEMO overlay
38- demoText = new FlxText (0 , 0 , FlxG .width , " DEMO" );
39- demoText .setFormat (null , 72 , FlxColor .YELLOW , " center" );
40- demoText .y = 120 ;
41- demoText .alpha = 1 ;
42- add (demoText );
43-
44- // Press Any Key overlay
45- pressAnyText = new FlxText (0 , 0 , FlxG .width , " Press Any Key" );
46- pressAnyText .setFormat (null , 40 , FlxColor .WHITE , " center" );
47- pressAnyText .y = FlxG .height - 120 ;
48- pressAnyText .alpha = 1 ;
49- add (pressAnyText );
5032
5133 buildVideoList ();
5234
5335 if (videos .length == 0 )
5436 {
5537 label .text = " No trailers found in: " + util. Paths .trailersDir ();
38+ add (label );
5639 // After a brief pause, go back
5740 new FlxTimer ().start (1.0 , _ -> FlxG .switchState (() -> new GameSelectState ()));
5841 return ;
5942 }
43+
6044 startNextVideo ();
61-
6245
46+ // Add overlays after video for correct layering
47+ add (label );
48+ demoText = new FlxText (0 , 0 , FlxG .width , " DEMO" );
49+ demoText .setFormat (null , 72 , FlxColor .YELLOW , " center" );
50+ demoText .y = 120 ;
51+ demoText .alpha = 1 ;
52+ add (demoText );
6353
54+ pressAnyText = new FlxText (0 , 0 , FlxG .width , " Press Any Key" );
55+ pressAnyText .setFormat (null , 40 , FlxColor .WHITE , " center" );
56+ pressAnyText .y = FlxG .height - 120 ;
57+ pressAnyText .alpha = 1 ;
58+ add (pressAnyText );
6459 }
6560
6661 override public function destroy (): Void
6762 {
68-
69- if (player != null )
63+ if (videoSprite != null )
7064 {
71- try
72- player .stop ()
73- catch (_ : Dynamic ) {}
74-
75- player .dispose ();
76- player = null ;
65+ videoSprite .destroy ();
66+ remove (videoSprite );
67+ videoSprite = null ;
7768 }
78-
7969 super .destroy ();
8070 }
8171
@@ -93,12 +83,11 @@ class AttractState extends FlxState
9383
9484 if (anyUserActivity ())
9585 {
96-
97- if (player != null )
86+ if (videoSprite != null )
9887 try
99- player .stop ()
88+ videoSprite .stop ()
10089 catch (_ : Dynamic ) {}
101-
90+ videoSprite = null ;
10291 FlxG .switchState (() -> new GameSelectState ());
10392 return ;
10493 }
@@ -128,15 +117,13 @@ class AttractState extends FlxState
128117 vidIdx = - 1 ;
129118 }
130119
131-
132120 function startNextVideo (): Void
133121 {
134122 if (videos .length == 0 )
135123 return ;
136124 vidIdx ++ ;
137125 if (vidIdx >= videos .length )
138126 {
139- // reshuffle each pass to keep it fresh
140127 FlxG .random .shuffle (videos );
141128 vidIdx = 0 ;
142129 }
@@ -147,22 +134,22 @@ class AttractState extends FlxState
147134 {
148135 label .text = " " ; // clear any messages
149136
150- // Stop and remove existing player
151- if (player != null )
137+ if (videoSprite != null )
152138 {
153- try
154- player .stop ()
155- catch (_ : Dynamic ) {}
156- player .dispose ();
157- player = null ;
139+ videoSprite .destroy ();
140+ remove (videoSprite );
141+ videoSprite = null ;
158142 }
159143
160- player = new FlxVideo ();
161- player .onEndReached .add (() -> startNextVideo ());
162- player .play (path , false ); // true = loop in codec; we'll still advance manually on complete for robustness
163-
144+ videoSprite = new FlxVideoSprite ();
145+ videoSprite .bitmap .onEndReached .add (() -> startNextVideo ());
146+ videoSprite .play (path , false );
147+ videoSprite .bitmap .volume = Std .int (FlxG .sound .volume * 100 );
148+ videoSprite .x = 0 ;
149+ videoSprite .y = 0 ;
150+ videoSprite .setGraphicSize (FlxG .width , FlxG .height );
151+ add (videoSprite ); // Add before overlays for correct layering
164152 }
165-
166153
167154 inline function anyUserActivity (): Bool
168155 {
0 commit comments