Be a Supporter!

(AS2) Displacement Map not working

  • 460 Views
  • 2 Replies
New Topic Respond to this Topic
FlamingCow
FlamingCow
  • Member since: Dec. 2, 2006
  • Offline.
Forum Stats
Member
Level 09
Game Developer
(AS2) Displacement Map not working Apr. 3rd, 2012 @ 10:48 AM Reply

I recently learned about the displacement map filter, and was like "cool, I should use that somehow".

So just for fun I decided to implement it in my current project's main menu.
Basically the background is a texture, programmed to scroll with the mouse direction. This done using begin bitmap fill and a transform matrix.

So far so good.

This background is then drawn onto a blank bitmap data object, and then tinted red for some reason.
(well because I was trying to get it to work, and while there is no good reason for it, I'm too lazy to change it back)

Anyway, part of logo then warps itself to the texture, using data I just made as it's map.

The problem is that instead of warping at all, the logo just "shakes" rapidly a few pixels. I've spent a few hours tweaking and playing with it, It doesn't seem to want to warp no matter what I do :( and to add insult to injury, there's nothing on google about this specific issue either.

My map, while mostly red, does have color variants so I see reason why it wouldn't warp a little.

tint = new ColorTransform(0, 1, 0, 0, 250, 0, 0, 0, 0);
	Mapbit.draw(_root.Background.Ass, new Matrix(), tint);
	var mapPoint:Point = new Point(_root.Mania._x-(_root.Mania._width/2), _root.Mania._y-(_root.Mania._height/2));
	var componentX:Number = 1;
	var componentY:Number = 1;
	var scaleX1:Number = 10;
	var scaleY1:Number = 10;
	var filter:DisplacementMapFilter = new DisplacementMapFilter(Mapbit, mapPoint, componentX, componentY, scaleX1, scaleY1);
	Mania.filters = [filter];

Note: Mania is the instance name of part of the logo I'm trying to warp.


Play my crappy Shmup!
Will I ever make a post without a typo? the world will ever know.

FlamingCow
FlamingCow
  • Member since: Dec. 2, 2006
  • Offline.
Forum Stats
Member
Level 09
Game Developer
Response to (AS2) Displacement Map not working Apr. 5th, 2012 @ 02:15 AM Reply

Alright so I just did a little experiment to make sure it wasn't how I was applying the filter.
Turns out the reason it jumps around has something to do with the way the timeline was set up. For each main loop, I usually have an onEnterFrame function key frame, then a few blank frames and a gotoandplay that returns the play head back to the onEnterFrame. Instead, by just having one key frame, it works perfectly as expected.

That doesn't explain why is didn't work at all though ...
In my experiment I recreated the jumping around issue, but the filter still worked on certain frames.

How it should look ...
Weird jumping crap ...

Now my question is, is there a work around for this? I really don't want to restructure my entire game for one filter effect, and probably wont ...


Play my crappy Shmup!
Will I ever make a post without a typo? the world will ever know.

FlamingCow
FlamingCow
  • Member since: Dec. 2, 2006
  • Offline.
Forum Stats
Member
Level 09
Game Developer
Response to (AS2) Displacement Map not working Apr. 5th, 2012 @ 12:28 PM Reply

Alright, I just about solved it. The jumping is related to the gotoAndPlay, or the play head moving at all.
Simply adding a stop function fixes it.


Play my crappy Shmup!
Will I ever make a post without a typo? the world will ever know.