Jump to content

How to animate particle in particle engine?


prateek.pradeep
 Share

Recommended Posts

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

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

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

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);  });
Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...