ForgeableSum Posted March 6, 2017 Share Posted March 6, 2017 Is there a way to make only certain pixels of a graphics object transparent? assuming the graphic was already filled with a solid color, then you could do something like: graphic.beginFill('transparent',1); graphic.drawCircle(0,0,100); So that would draw a little circle with transparent pixels? I am using a bitmap data to achieve a similar effect and it is just way too resource-intensive to draw to a BMD on every update call. Link to comment Share on other sites More sharing options...
ForgeableSum Posted March 7, 2017 Author Share Posted March 7, 2017 Anyone? I've tried about 1000 things. Still can't figure out a way to do something like this. And I've found tons of old posts of people asking the same thing in different words. The idea is simple: fill a graphics or render texture and draw a shape, like a circle or ellipses with transparency. Right now there seems to be no way to do something like this without using a bitmap data. But surely, that couldn't be true. Because erasing stuff, with more specific criteria than "the entire thing" is a fundamental and basic drawing operation. Yet it would seem render textures and graphics only allow you to clear the entire thing, and not certain areas. Link to comment Share on other sites More sharing options...
samme Posted March 7, 2017 Share Posted March 7, 2017 I have to guess transparent fills can't actually remove other fills. But maybe you could fill black/white and use a blendMode? Link to comment Share on other sites More sharing options...
ForgeableSum Posted March 7, 2017 Author Share Posted March 7, 2017 1 minute ago, samme said: I have to guess transparent fills can't actually remove other fills. But maybe you could fill black/white and use a blendMode? I can't conceive of how blend modes could be used in render textures or graphics. Using destination-out blendmode in a bmd gets the job done, but it's horrible on performance. How do you imagine using blend modes in a render texture or graphic? Link to comment Share on other sites More sharing options...
Milton Posted March 7, 2017 Share Posted March 7, 2017 2 hours ago, feudalwars said: Because erasing stuff, with more specific criteria than "the entire thing" is a fundamental and basic drawing operation. Yet it would seem render textures and graphics only allow you to clear the entire thing, and not certain areas. HTML Canvas supports clearRect(), so you could add that to Phaser's CanvasRenderer. Add some sort of clearObject, similar to how a Mask is used. Then as the final step on render, do some clever clearRecting You would have to do everything with Rects of course, could be fun. For the WebGLRenderer it should be easier to implement, you can just render your transparent clearObject. Link to comment Share on other sites More sharing options...
squilibob Posted March 9, 2017 Share Posted March 9, 2017 Am I missing something in this topic or can you simply just apply a mask to your graphics object? Link to comment Share on other sites More sharing options...
ForgeableSum Posted March 9, 2017 Author Share Posted March 9, 2017 5 hours ago, squilibob said: Am I missing something in this topic or can you simply just apply a mask to your graphics object? A mask is only going to give you a rectangular shape and it will only show the parts of the graphics object that are inside the mask. But what I want is the opposite, to only show the negative space (making the pixels inside the mask area transparent). So yeah, a mask is not the solution. A reverse mask that allows shapes other than rectangles would be. Link to comment Share on other sites More sharing options...
samme Posted March 10, 2017 Share Posted March 10, 2017 rblopes and Milton 2 Link to comment Share on other sites More sharing options...
samme Posted March 11, 2017 Share Posted March 11, 2017 Link to comment Share on other sites More sharing options...
JeanPeel Posted April 10, 2020 Share Posted April 10, 2020 You need to make your graphics into PNG's with transparency. Here is an online editor that does it well. https://www5.lunapic.com/editor/?action=transparent Then Phaser will load it into the game with the transparency already recorded in the PNG. Link to comment Share on other sites More sharing options...
Recommended Posts