Edit: see notes at the bottom of this post as well.
Sine-wave Distortion for Actors (for Stencyl 3.0, all platforms)
Attached to this post This Pastebin file is an Actor Behavior that allows you to apply a sine-wave warping/distortion effect to the actor's image. Some explanation of the settings available are below, but you will probably have to do some tests to get it to look as desired for your particular scenario.
Note that this is designed to work on single-frame actors and will probably not function as expected with animated (multi-frame) actors' images. Scaling images has been reported to also break the effect.
Eventually, I aim to see about implementing this as a scene behavior to apply to the screen on demand.
As the behavior is now on Pastebin, everyone should be able to add it to their game. To do so, create a new Actor Behavior, in code mode. Name it whatever you like, and the Classname field can be whatever is there already. From inside the code mode behavior editor, paste the
entire contents of the pastebin file into the behavior. You need to completely replace everything that was in there previously by default. After it is in there, press the "Refresh Attributes" button.
If you feel compelled, you can still use the PNG image attached as the icon for the behavior.
Note that if you happen to have another behavior with the exact same classname (see line 61) Stencyl will give you errors when you compile. This can happen if you create a duplicate of a code mode behavior, so keep that in mind.
AttributesOrientationThis number attribute sets the "orientation" of the waves. Specifically, setting it to 0 (zero) will result in the behavior modifying
rows of pixels in the actor's image. Any other value will cause it to modify
columns of pixels of the image. This also means that the waves appear to move toward the top when set to 0, or to the right otherwise.
Note that you can reverse the direction of motion; see the Frameskip attribute below.
DirectionThis number attribute sets the "direction" of the waves' motion. Specifically, setting it to 0 (zero) will result in the behavior to shift the rows/columns (as determined by the orientation value) in a left/right motion. Any other value will cause the rows/columns to shift in an up/down motion.
FrameskipA number value that allows you to set the speed of the wave motion. A value of 0 (zero) will result in no motion, although the effect will still be present. Positive values will move the waves "upward" or "rightward" and negative values will move "downward" or "leftward". The further from zero the value, the greater the speed of motion.
FrequencyThis number value sets the width of the wave (technically, peak-to-peak measurement). Counter-intuitively, a value of 0 (zero) represents the entire width or height of the image (motion without distortion). A value of 2 is the maximum recommended, and appears to represent every-other row/column. The ideal value for a particular use will be closely related to the Amplitude value, but values of .01 to .5 seem to produce good results. This value can also be negative, to mirror the effect.
AmplitudeThis number value is the maximum number of pixels the wave will shift a row or column. Since the edges of the image are not redrawn or rendered transparent, some degree of transparency padding (equal to the amplitude, for example), or the use of similar colors at the edge, will help avoid visible "stretching" issues with higher amplitude settings.
CreditsSpecial thanks to Irock who provided the request and inspiration for this behavior. Without him it would not exist.
The algorithm for the sine-wave motion itself comes from
Earthbound Battle Backgrounds. While the sine-wave formula is well documented, having an existing version to work with greatly simplified the task.
Some of the code from Rob's
Set Screenshot To Actor was extremely helpful in accessing the BitmapData and ensuring cross-platform compatibility.
MdotEdot also performed some device testing for the initial version.
Thanks to all the above. Enjoy, everyone!
Last night and this morning I was working on a way to distort an Actor's BitmapData in a sine-wave pattern. This is the result. I'll share the behavior eventually once I clean it up some.
http://www.stencyl.com/game/play/24401
For other people:
http://pastebin.com/hR71TKYA
Name your new Actor Behavior "Distortion", select Code Mode, and give it a classname of "Design_12_12_Distortion" (from line 62 of the above pastebin file). If you use a different classname, you'll have to alter that line to match instead.
Make sure you click "Refresh Attributes" after pasting the file into the behavior. All other instructions are valid. Let me know if this fails as I'm short on testing time right now.