Flash怎么制作滚动字幕动画效果
发布网友
发布时间:2022-05-12 12:08
我来回答
共1个回答
热心网友
时间:2023-10-08 23:13
闲时做的一个歌词滚动模板,AS3.0一起学习了。
这是一个静态类,它是歌词及显示时间。
package
{
public class lyricAndTimer
{
public static const lyric0:String = "冷冷的夜里北风吹.";
public static const lyric1:String = "找不到人安慰`";
public static const lyric2:String = "当初的誓言太完美``";
public static const lyric3:String = "让相思化成灰``";
public static const lyric4:String = "冷冷的夜里北风吹`";
public static const lyric5:String = "找不到人安慰``";
public static const lyric6:String = "当初的誓言太完美``";
public static const lyric7:String = "让相思化成灰``";
public static const lyric8:String = "花开的时候最珍贵<>";
public static const lyric9:String = "花落了就枯萎<>";
public static const lyric10:String = "错过了花期花怪谁<>";
public static const lyric11:String = "花需要人安慰<>";
public static const lyric12:String = "冷艳2017-1-17<>";
public static const playTime:Array = [0,3,7,11,15,19,23,27,31,35,39,43,48];
}
}
这是一个创建文本的类:
package
{
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Sprite;
import flash.geom.Point;
public class typeLyric extends Sprite
{
private var tip:TextField = new TextField ;
private var format:TextFormat = new TextFormat ;
private var _hue:uint;
public function typeLyric(lyric:String)
{
format.size = 30;
tip = new TextField ;
addChild(tip);
tip.alpha = 1;
tip.selectable = false;
tip.defaultTextFormat = format;
tip.text = lyric;
tip.height = tip.textHeight;
tip.width = tip.textWidth ;
tip.x = 0;
tip.y = 0;
}
public function set hue(color:uint):void
{
_hue = color;
tip.textColor = _hue;
}
}
}
设置文本滚动速度和显示颜色:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
public class createLyric extends Sprite
{
private var cly:typeLyric;
private var _speed:Number = 0;
public function createLyric(lyric:String )
{
cly = new typeLyric(lyric);
cly.x = 50;
addChild(cly);
}
public function get speed():Number
{
return _speed;
}
public function set speed(num:Number ):void
{
_speed = num;
cly.addEventListener(Event.ENTER_FRAME,loop);
}
private function loop(e:Event ):void
{
cly.y -= _speed;
var clyP:Point =cly.localToGlobal(new Point (0,0));
if (clyP.y > 320 && clyP.y<350)
{
cly.hue = 0xff0000;
}
else
{
cly.hue = 0x000033;
}
if (clyP.y < 280)
{
removeChild(cly);
cly.removeEventListener(Event.ENTER_FRAME,loop);
}
}
}
}
最后绑定falsh
package
{
import flash.display.Sprite;
import flash.events.Event;
public class setLyric extends Sprite
{
private var lys:String = new String ();
private var lyn:int = -1;
private var ly:createLyric;
private var lyricNum:uint = 13;
private var lyarr:Array = new Array ;
private var quanta:Number = 0;
private var speed:Number = 0;
private var sp:Sprite = new Sprite ;
public function setLyric()
{
for (var i:int =0; i<lyricNum; i++)
{
lyarr.push(lyricAndTimer["lyric"+i]);
}
stage.addEventListener(Event.ENTER_FRAME,loop);
addChild(sp);
}
private function loop(e:Event ):void
{
if (quanta>24)
{
lyn++;
for (var i:uint =0; i< lyricNum; i++)
{
if (lyn==lyricAndTimer.playTime [i])
{
lys = lyarr[i];
ly = new createLyric(lys);
ly.y = 360+i*30+i;
ly.speed = 0;
sp.addChild(ly);
speed = 30/((lyricAndTimer.playTime[i + 1] - lyricAndTimer.playTime[i])*24);
if (isNaN(speed))
{
speed= 30/((lyricAndTimer.playTime[i] - lyricAndTimer.playTime[i-1]) *24);
}
}
}
quanta = 0;
}
else
{
quanta++;
}
sp.y-=speed
if (lyn==lyricAndTimer.playTime [lyricAndTimer.playTime .length-1]+15)
{
stage.removeEventListener(Event.ENTER_FRAME,loop);
lyn = 0;
}
}
}
}
效果不是很好,有待改善。仅供参考。