Silverlight 2.5D RPG游戏技巧与特效处理:(七)动画特写
时间:2011-03-23 来源:深蓝色右手
还记得Shazzam吗?要制作特写依旧离不开这款强大的工具,以角色的传送特写“幻降”为例,对应Shazzam中的现成特效名为:DirectionalBlur,我们不妨看看它的HLSL代码:
float Angle : register(C0);float BlurAmount : register(C1);
sampler2D Texture1Sampler : register(S0);
float4 main(float2 uv : TEXCOORD) : COLOR
{
float4 c = 0;
float rad = Angle * 0.0174533f;
float xOffset = cos(rad);
float yOffset = sin(rad);
for(int i=0; i<16; i++)
{
uv.x = uv.x - BlurAmount * xOffset;
uv.y = uv.y - BlurAmount * yOffset;
c += tex2D(Texture1Sampler, uv);
}
c /= 16;
return c;
}
仅仅十来行不到1KB的代码,将之按照第5节的方法配置进游戏项目后,在角色传送结束时我们便通过Storyboard创建基于DirectionalBlur参数为BlurAmount的动画实现360任意角度的幻影过度动画特写:
DirectionalBlur directionalBlur = new DirectionalBlur() { Angle = 90 };entity.Effect = directionalBlur;
Storyboard blurStoryboard = new Storyboard();
DoubleAnimation doubleAnimation = new DoubleAnimation() {
From = -0.25,
To = 0,
Duration = new Duration(TimeSpan.FromMilliseconds(600)),
};
Storyboard.SetTarget(doubleAnimation, directionalBlur);
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("BlurAmount"));
blurStoryboard.Children.Add(doubleAnimation);
EventHandler handler = null;
blurStoryboard.Completed += handler = (s1, e1) => {
Storyboard sb = s1 as Storyboard;
sb.Stop();
sb.Completed -= handler;
entity.Effect = null;
};
blurStoryboard.Begin();
某些场合为了突出玩家隆重登场,我们通常还会使用到比如“影合”(GrowablePoissonDisk)的动画特写:无数个角色的重影由四面八方汇聚而来,如同灵魂与力量的回归附体:
某些时候角色从一个空间向另外一个空间穿梭,虚幻的感受是身体被分解成粒子最终从下至上又被重新组合,此时常会用到“新生”(CircleReveal)动画特写来描述这样一个穿越生死的经历:
当然,发自内心的希望更多的Silverlight开发者能融入到HLSL的编写中,实现并分享更多更加炫酷的动画特效为Silverlight将来一统三端打下基础。不远了,Silverlight 5 发布后游戏开发都会易如反掌,一切特效在Silverlight面前将一文不值。我始终坚信:追求极致的心必定银光四射,长空千里!
在线演示地址:http://silverfuture.cn
相关阅读 更多 +