55 * Public License, v. 2.0 that can be found in the LICENSE file.
66 */
77
8- import { autoDetectRenderer } from 'pixi.js' ;
8+ import { autoDetectRenderer , Container } from 'pixi.js' ;
99import { framesToMillis , Timestamp , FPS_DEFAULT } from '../models' ;
1010import { MediaClip } from '../clips' ;
1111import { Serializer } from '../services' ;
1212import { TrackDeserializer } from '../tracks' ;
13- import { clear } from '../utils/pixi' ;
1413import { isClass } from '../utils' ;
1514import { EventEmitterMixin } from '../mixins' ;
1615import { BaseError } from '../errors' ;
@@ -35,6 +34,11 @@ export class Composition extends EventEmitterMixin<CompositionEvents, typeof Ser
3534 */
3635 public renderer ?: Renderer ;
3736
37+ /**
38+ * The root container of the composition
39+ */
40+ public stage = new Container ( ) ;
41+
3842 /**
3943 * Settings of the composition
4044 */
@@ -95,7 +99,7 @@ export class Composition extends EventEmitterMixin<CompositionEvents, typeof Ser
9599 this . on ( 'frame' , this . computeFrame . bind ( this ) ) ;
96100 this . on ( 'error' , this . computeFrame . bind ( this ) ) ;
97101
98- autoDetectRenderer ( { ...this . settings , clearBeforeRender : false , preference : backend } )
102+ autoDetectRenderer ( { ...this . settings , preference : backend } )
99103 . then ( renderer => {
100104 this . renderer = renderer ;
101105 this . trigger ( 'init' , undefined ) ;
@@ -196,6 +200,7 @@ export class Composition extends EventEmitterMixin<CompositionEvents, typeof Ser
196200
197201 track . connect ( this ) ;
198202
203+ this . stage . addChild ( track . view ) ;
199204 this . tracks . unshift ( track ) ;
200205
201206 track . on ( '*' , this . updateDuration . bind ( this ) ) ;
@@ -301,13 +306,13 @@ export class Composition extends EventEmitterMixin<CompositionEvents, typeof Ser
301306 */
302307 public computeFrame ( ) : void {
303308 if ( ! this . renderer ) return ;
304-
305- clear ( this . renderer , this . context ) ;
306-
307- for ( let i = this . tracks . length - 1 ; i >= 0 ; i -- ) {
308- this . tracks [ i ] . render ( this . renderer , Timestamp . fromFrames ( this . frame ) ) ;
309+
310+ for ( let i = 0 ; i < this . tracks . length ; i ++ ) {
311+ this . tracks [ i ] . update ( Timestamp . fromFrames ( this . frame ) ) ;
309312 }
310313
314+ this . renderer . render ( this . stage ) ;
315+ this . context ?. clearRect ( 0 , 0 , this . settings . width , this . settings . height ) ;
311316 this . context ?. drawImage ( this . renderer . canvas , 0 , 0 ) ;
312317
313318 this . trigger ( 'currentframe' , this . frame ) ;
@@ -372,7 +377,7 @@ export class Composition extends EventEmitterMixin<CompositionEvents, typeof Ser
372377 await track . seek ( Timestamp . fromFrames ( this . frame ) ) ;
373378 }
374379
375- this . timerCallback ( ) ;
380+ this . ticker ( ) ;
376381 this . trigger ( 'play' , this . frame ) ;
377382 }
378383
@@ -456,7 +461,7 @@ export class Composition extends EventEmitterMixin<CompositionEvents, typeof Ser
456461 ) ;
457462 }
458463
459- private async timerCallback ( ) {
464+ private async ticker ( ) {
460465 const interval = 1000 / FPS_DEFAULT ;
461466
462467 let then = performance . now ( ) ;
0 commit comments