Jump to content

Making Particle Color Match Sprite Color


coder_for_life22
 Share

Recommended Posts

Hey Everyone, Pretty new here but glad to be a part of the community. 

 

Question, I have a game with sprites that are all of the same prefab but the only difference is the actually image of the sprites. The issue is, when one of these objects are destroyed in my game I would like to show particles for each sprite being destroyed. Currently, I have the particles working but I would like to somehow make the particles match the color of the sprite it represents.

Does anyone know how I can do this when I create each sprite or maybe somehow detect the color of each sprite? 

All of these sprites are being pooled using groups, if that makes a difference. 

 

Thanks guys

Link to comment
Share on other sites

  • 5 weeks later...

How about adding a particle color property to your sprites then use dynamic texture generation?

You can use ctx.getImageData to obtain the 8bit rgba value for any particular pixel in your canvas if this must be done at runtime.

https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getImageData

https://phaser.io/examples/v2/particles/particle-class

//  Create our bitmapData which we'll use as our particle texture
    var bmd = game.add.bitmapData(64, 64);

    var radgrad = bmd.ctx.createRadialGradient(32, 32, 4, 32, 32, 32);

    radgrad.addColorStop(0, 'rgba(1, 159, 98, 1)');
    radgrad.addColorStop(1, 'rgba(1, 159, 98, 0)');

    bmd.context.fillStyle = radgrad;
    bmd.context.fillRect(0, 0, 64, 64);

    //  Put the bitmapData into the cache
    game.cache.addBitmapData('particleShade', bmd);

 

Link to comment
Share on other sites

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...