This topic is somehow related to a topic I previously posted:
I am using this beginGradientFill code from the previous topic to make a hole on an image with BlendMode.ALPHA. If I do this once, the game runs perfectly. However, if I update the hole every frame (necessary to give a “breathing effect” to the hole) the framerate drops drastically.
I believe once you use this, it triggers software rendering, which could explain the performance difference. Can you cache the result using bitmapData.draw, or does it need to continue to dynamically update?
Unfortunately I have to dinamically update it. I have a sinoidal function operating on the radius of the hole like this:
This video shows the game running with the gradientFill approach, not making a hole on an image. If I try to make this effect happen on an image the game is not playable =/
Do you happen to know any alternative to get this kind of effect?
Hmm, I suppose there are two main ways to go about it:
You have a large black object, and you punch a hole through it
You have a round object that fades to black that you lay over things, then you mask the rest of things out
If I were to try and think of a faster way to implement it, I might try doing path #1 using a large object (that I rendered overly large) then I try scaling it up or down based on the shadow size
If I were to try #2, I would use a scrollRect to do the full alpha cut-off, then draw a shape in order to handle the remaining part of the hole. This I would also consider caching and scaling as needed
Thanks! I will try both approaches and post the results soon =)
EDIT
Just thought a little bit more about the two approaches and I won’t be able to use them.
#1 would work with a full black background, but the image I need to puch a hole through has a texture, so it is visible that it is scaling
#2 is fine for the cenario I showed on the video, but the next step in the game is to make this hole open and show the whole scene. If I do this, I get the framerate drop again because the scrollRect would have to have the size of the whole screen.
I guesst I will just keep using the gradient fill and give up on using that image. Thanks for the help!