Last active
February 29, 2020 09:35
-
-
Save PrimaryFeather/5983685 to your computer and use it in GitHub Desktop.
Water distortion filter, implemented with Starling's "DisplacementMapFilter".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function addDistortionTo(target:DisplayObject):void | |
{ | |
var offset:Number = 0; | |
var scale:Number = Starling.contentScaleFactor; | |
var width:int = target.width; | |
var height:int = target.height; | |
var perlinData:BitmapData = new BitmapData(width * scale, height * scale, false); | |
perlinData.perlinNoise(200*scale, 20*scale, 2, 5, true, true, 0, true); | |
var dispMap:BitmapData = new BitmapData(perlinData.width, perlinData.height * 2, false); | |
dispMap.copyPixels(perlinData,perlinData.rect, new Point(0,0)); | |
dispMap.copyPixels(perlinData,perlinData.rect, new Point(0,perlinData.height)); | |
var texture:Texture = Texture.fromBitmapData(dispMap, false, false, scale); | |
var filter:DisplacementMapFilter = new DisplacementMapFilter(texture, null, | |
BitmapDataChannel.RED, BitmapDataChannel.RED, 40, 5); | |
target.filter = filter; | |
target.addEventListener("enterFrame", function(event:EnterFrameEvent):void | |
{ | |
if (offset > height) offset -= height; | |
else offset += event.passedTime * 20; | |
filter.mapPoint.y = offset - height; | |
}); | |
} |
thanks
cool!
Hi Daniel,
Thanks for the example.
I have a little issue with the rendering : each time offset > height, I have a little freeze on the animation... and I can't manage to run it smoothly...
Any idea?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great!