prateek.pradeep Posted June 19, 2015 Share Posted June 19, 2015 Hey,Does anybody has an idea on how to animate particles in particle system. I want a spritesheet animation playing on all particles, while these particles roam randomly. Below is the code which I am trying but its not working.function CubeParticle(game, x, y) { window.Phaser.Particle.call(this, game, x, y, game.cache.getRenderTexture('cubeParticle'));}CubeParticle.prototype = Object.create(window.Phaser.Particle.prototype);CubeParticle.prototype.constructor = CubeParticle;function create(){var particle = game.add.sprite(400, 800, 'particles'); particle.animations.add('particleAnim'); particle.animations.play('particleAnim', 30, true); game.sa.gameLayers[layer.slot].add(particle); game.cache.addRenderTexture('cubeParticle', particle); var emitter = game.add.emitter(game.world.centerX, 200, 200); emitter.width = 800; emitter.particleClass = CubeParticle; emitter.makeParticles(); // THIS LINE THROWS AN ERROR "Cannot read property 'hasLoaded' of undefined"...........} Link to comment Share on other sites More sharing options...
drhayes Posted June 19, 2015 Share Posted June 19, 2015 That "create() {..." looks syntax errorish? Is that an ES2015 class or something? Put the code defining the animations inside your constructor function, not as that sprite you define later in the create function. The result of that "getRenderTexture" call probably doesn't produce anything. Why not pass the string 'cubeParticle', is it not already in the cache? Link to comment Share on other sites More sharing options...
rgk Posted June 20, 2015 Share Posted June 20, 2015 it seems like your making this more complex then you need.Also triggering play after makeParticles might make more sense. Use emitter like group. Link to comment Share on other sites More sharing options...
prateek.pradeep Posted June 20, 2015 Author Share Posted June 20, 2015 That "create() {..." looks syntax errorish? Is that an ES2015 class or something? I am sorry about create method. I have corrected it in my question.The getRenderTexture method in my custom particle class throws error, when I try to make particles from emitter. Is animation in texture no supported or what?I cannot figure what you are trying to say. Could you be more wordy please. Link to comment Share on other sites More sharing options...
prateek.pradeep Posted June 21, 2015 Author Share Posted June 21, 2015 Anyone???Richie can you help??? Link to comment Share on other sites More sharing options...
prateek.pradeep Posted June 21, 2015 Author Share Posted June 21, 2015 Well found it.While creating particles, iterate on all the sprite in emitter and add and play each particle animation. // enable particle animation of all particles emitter.forEach(function(singleParticle) { singleParticle.animations.add('particleAnim'); singleParticle.animations.play('particleAnim', 30, true); }); TaylorN 1 Link to comment Share on other sites More sharing options...
tinyflea Posted July 2, 2016 Share Posted July 2, 2016 thanks for this prateek.... works a treat Link to comment Share on other sites More sharing options...
Recommended Posts