1 decade ago by quidmonkey
I'm trying to implement a particle system for my Breakout-style game similar to the one used in Biolab. I copied and added particle.js, and created several Entity particle classes named EntityParticleBlock + Color (where Color is the corresponding color of the block i.e. EntityParticleBlockRed, EntityParticleBlockBlue, etc.). These child classes are sub-classed from this parent:
I embedded the particle logic in the parent Block class using the logic from Biolab's debris.js:
When I run this, I'm getting the following error in the console:
I'm guessing spawnEntity() is unable to initialize the object, although I don't know why. Any ideas? Maybe I did to change to restructure my code?
ig.module( 'game.entities.particle-block' ) .requires( 'game.entities.particle' ) .defines(function(){ EntityParticleBlock = EntityParticle.extend({ lifetime: 2, fadetime: 1, bounciness: 0.6, vel: {x: 60, y: 20}, size: {x: 4, y: 8}, animSheet: new ig.AnimationSheet( 'media/particle-red.png', 4, 8 ), init: function( x, y, settings ) { this.parent( x, y, settings ); this.addAnim( 'idle', 1, [0] ); } }); });
I embedded the particle logic in the parent Block class using the logic from Biolab's debris.js:
update: function(){ if (this.state == 'dead') { if( this.durationTimer.delta() < 0 && this.nextEmit.delta() >= 0) { this.nextEmit.set( this.duration / this.count ); var x = Math.random().map( 0, 1, this.pos.x, this.pos.x + this.size.x ); var y = Math.random().map( 0, 1, this.pos.y, this.pos.y + this.size.y ); var particle = 'EntityParticleBlock' + this.color; ig.game.spawnEntity(particle, x, y ); } else { this.kill(); } } this.parent(); },
When I run this, I'm getting the following error in the console:
Uncaught TypeError: Cannot read property 'flip' of null
I'm guessing spawnEntity() is unable to initialize the object, although I don't know why. Any ideas? Maybe I did to change to restructure my code?