I'm building a game on Starling 1.6 and I'm wondering if there's some way to detect the color of a flattened Sprite under a specified point?
The matter is that I have character container which lays right under another container that may contain shadows (semi-transparent images). The whole shadow container is flattened and the images inside have the blend mode of MULTIPLY.
I also have shot flashes, which are also images with blend mode of ADD and I put these images on top of the shadows container when the player shoots, so there's an effect of "fake lights" when they're necessary. But I want to disable those shots if there's no shadows at a particular place of location. That's why I need to check the level of alpha channel over some point
Is that possible?
Is it possible to check if there's opaque or semi-transparent pixel(6 posts) (2 voices)
In one sense no: you cannot easily read back the state of a pixel, as you could in the classic Flash API. What you have to do is what you are doing: use blend modes to combine pixels, which in most cases involves reading the destination pixel as part of the blend mode.
The other thing you can do is render into a texture, and it sounds like you are doing that when you flatten things. But consider doing it for the whole layer, so your lights are rendered into the layer with the shots.
And you might need a custom BlendMode, as none of the built in ones obviously do what you want, but you can register your own: something like
But you probably need to try it out and see what works with your design.
You've probably misunderstood me a little. The built-in blend modes do exactly what I need. It looks almost perfect. I just need to disable the whole effect when the overlay is completely transparent. That's it. There's no need to render anything at all when it's bright day in the game, the effect is only necessary in some basements and stuff like that.
As to rendering to a texture, it won't give any effect
It looks pretty good here http://prnt.sc/em6g45
But too bright here http://prnt.sc/em6h6o
You are right I was unclear what you were looking for. The blendmode I describe above is meant to do what I thought you were in particular looking for: "Context3DBlendFactor.DESTINATION_ALPHA" for the source factor tells it to only draw the source (the light) when there is something in the destination (the shadow).
Don’t forget you can use multiple blend modes in your render pipeline. Render into a texture with one, then render that into the scene or into another texture with another. This could get quite expensive, but if it achieves the result you want might be worth doing. And in theory it’s simple to speed up rendering with RenderTextures by not updating them every frame, and deferring the most expensive stuff to updates done only every few frames.
Render into a texture with one, then render that into the scene or into another texture with another.
That's what I'm doing right now, and you can see the results on the screenshots
And in theory it’s simple to speed up rendering with RenderTextures
I tried this approach about a half a year ago for the same game. If the operation is heavy it won't matter if I do it every frame or every few frames, the whole game will freeze anyway. But it's not what I'm worried about. By now the game is pretty well optimized and it outputs 58 - 60 stable fps so I'm not looking for further optimizations at the moment
I only want to find the best approach to disable the shot flash systems and it seems like the best way would be to specify these "disable/enable" zones manually inside the level editor
Yes, if you can identify where it’s needed (and the backgrounds in your screenshots look pretty static) that would be probably ideal; use simple sprites which are turned on and off as needed.
I did think of another way to do it automatically. With AGAL. In code you could easily work out the brightness of the background and draw the light with appropriate brightness. The problem is AGAL works on textures, you can’t treat it as a blend mode. The only way would be to encapsulate it in a filter which would effectively apply the light or lights to the whole scene. A lot of coding and possibly quite expensive, performance wise.
Another gotcha is: my experience with AGAL is with Starling 2, and one of the things that changed from Starling 1 was filters. But I don’t think they changed in a way that would stop this being possible.
You must log in to post.