coder_for_life22 Posted March 4, 2018 Share Posted March 4, 2018 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 Quote Link to comment Share on other sites More sharing options...
SirFizX_ELHS Posted April 2, 2018 Share Posted April 2, 2018 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); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.