@@ -6,6 +6,7 @@ class Graphics extends me.Renderable {
66 super ( 0 , 0 , engine . width , engine . heigth ) ;
77 this . engine = engine ;
88 this . anchorPoint . set ( 0 , 0 ) ;
9+ me . state . change ( me . state . DEFAULT , true ) ;
910
1011 // Particle creation
1112 const particles = new Array ( engine . count ) ;
@@ -18,9 +19,19 @@ class Graphics extends me.Renderable {
1819 3 * Math . random ( ) * rnd [ Math . floor ( Math . random ( ) * 2 ) ] ,
1920 3 * Math . random ( ) * rnd [ Math . floor ( Math . random ( ) * 2 ) ] ,
2021 ] ;
21- particles [ i ] = { x, y, size : size , dx, dy } ;
22+ let sprite ;
23+ if ( engine . type === 'sprite' ) {
24+ sprite = new me . Sprite ( x , y , {
25+ image : '/sprite.png' ,
26+ framewidth : 64 ,
27+ frameheight : 64 ,
28+ anchorPoint : new me . Vector2d ( 0.5 , 0.5 ) ,
29+ } ) ;
30+ me . game . world . addChild ( sprite ) ;
31+ }
32+ particles [ i ] = { x, y, size : size , dx, dy, el : sprite } ;
2233 }
23- this . particles = particles ;
34+ engine . particles = particles ;
2435 }
2536 update ( ) {
2637 return true ;
@@ -30,7 +41,7 @@ class Graphics extends me.Renderable {
3041 renderer . setColor ( '#ffffff' ) ;
3142
3243 // Particle animation
33- const particles = this . particles ;
44+ const particles = this . engine . particles ;
3445 for ( let i = 0 ; i < this . engine . count ; i ++ ) {
3546 const r = particles [ i ] ;
3647 r . x -= r . dx ;
@@ -41,11 +52,13 @@ class Graphics extends me.Renderable {
4152 else if ( r . y > this . engine . height ) r . dy *= - 1 ;
4253 if ( this . engine . type === 'stroke' )
4354 renderer . strokeArc ( r . x , r . y , r . size , 0 , Math . PI * 2 ) ;
44- if ( this . engine . type === 'fill' ) {
55+ else if ( this . engine . type === 'fill' ) {
4556 renderer . setColor ( '#ffffff' ) ;
4657 renderer . fillArc ( r . x , r . y , r . size , 0 , Math . PI * 2 , false ) ;
4758 renderer . setColor ( '#000000' ) ;
4859 renderer . strokeArc ( r . x , r . y , r . size , 0 , Math . PI * 2 , false ) ;
60+ } else if ( this . engine . type === 'sprite' && r . el ) {
61+ r . el . pos . set ( r . x , r . y ) ;
4962 }
5063 }
5164 this . engine . fpsmeter . tick ( ) ;
@@ -64,6 +77,7 @@ class MelonEngine extends Engine {
6477 window . cancelAnimationFrame ( this . request ) ;
6578
6679 // Create if new, else reset/empty the game world
80+ this . textureLoaded = false ;
6781 if ( me . game . world ) {
6882 me . game . world . reset ( ) ;
6983 } else {
@@ -76,9 +90,22 @@ class MelonEngine extends Engine {
7690 subPixel : false ,
7791 } ) ;
7892 }
93+ me . loader . preload (
94+ [
95+ {
96+ name : 'sprite' ,
97+ type : 'image' ,
98+ src : '/sprite.png' ,
99+ } ,
100+ ] ,
101+ ( ) => {
102+ this . textureLoaded = true ;
103+ this . render ( ) ;
104+ }
105+ ) ;
79106 }
80107 render ( ) {
81- me . game . world . addChild ( new Graphics ( this ) ) ;
108+ if ( this . textureLoaded ) me . game . world . addChild ( new Graphics ( this ) ) ;
82109 }
83110}
84111
0 commit comments