使用Numbercript中的基本Tween类使用数值补间Pixeling Pixel Bender过滤器

时间:2010-03-04 10:57:39

标签: actionscript-3 tween pixel-bender

我在学习Pixel Bender。我有一个过滤器谁想要补间参数。据我所知,为了补间像素弯曲参数,我需要补间一个数字对象,并将补间数字对象指定为着色器数据的数组值。

我确信以下方法可行,但似乎Number类没有value属性,所以我不知道在为数字对象设置新的补间时要使用什么属性:

import fl.transitions.*;
import fl.transitions.easing.*

var shader:Shader;
var shaderFilter:ShaderFilter;
var motionTween:Tween;
var tweenNumber:Number = new Number(0.0);
var loader:URLLoader = new URLLoader();

loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, dataLoaded);
loader.load(new URLRequest("PBFilter.pbj"));

function dataLoaded(e:Event):void
    {
    loader.removeEventListener(Event.COMPLETE, dataLoaded);
    shader = new Shader(e.target.data);
    shaderFilter = new ShaderFilter(shader);
    flower.filters = [shaderFilter];

    motionTween = new Tween(tweenNumber, "value", Bounce.easeOut, 0.0, 100.0, 5, true);
    motionTween.addEventListener(TweenEvent.MOTION_CHANGE, updateFilter);
    }

function updateFilter(e:TweenEvent):void
    {
    shader.data.amount.value = [tweenNumber];
    myMovieClip.filters = [shaderFilter];
    }

1 个答案:

答案 0 :(得分:3)

也许您可以为补间添加一个getter和setter到您的测试类中:

//...
public function get amount():Number {
 return tweenNumber;
}
public function set amount(value:Number):void {
 tweenNumber=value;
}
//...
motionTween = new Tween(this, "amount", Bounce.easeOut, 0.0, 100.0, 5, true);
motionTween.addEventListener(TweenEvent.MOTION_CHANGE, updateFilter);
//...

- 或更新到您的setter

//...
public function get amount():Number {
 return tweenNumber;
}
public function set amount(value:Number):void {
 tweenNumber=value;
 shader.data.amount.value = [value];
 myMovieClip.filters = [shaderFilter];
}
//...
motionTween = new Tween(this, "amount", Bounce.easeOut, 0.0, 100.0, 5, true);
//...