这种效果做法很多,网上到处可以搜出一大堆!本例主要是应用了BitmapData类,仿制很轻易。
做法:
处理一张首尾相接的环绕图片,导入Flash库中,打开库,右击图片,选“链接”,“为ActionScript导出“,标识ID名为:pic 。场景上什么也不放。最好将场景高度设为与图片一样高。宽度随意,但要小于图片宽度。
在第一帧粘帖如下代码,即可测试:
import flash.display.BitmapData;
import flash.geom.*;
//从库里取图
var picBD:BitmapData = BitmapData.loadBitmap("pic");
var pic_mc:MovieClip = this.createEmptyMovieClip("pic_mc", this.getNextHighestDepth());
pic_mc.attachBitmap(picBD, this.getNextHighestDepth());
//创建用于“过渡”的图
var picBD2:BitmapData = new BitmapData(Stage.width*2, pic_mc._height, false, 0xFF);
var pic_mc2:MovieClip = this.createEmptyMovieClip("pic_mc2", this.getNextHighestDepth());
pic_mc2.attachBitmap(picBD2, this.getNextHighestDepth());
//截取源图的前和后各一部分组成新的图
picBD2.copyPixels(picBD, new Rectangle(0, 0, Stage.width, pic_mc._height), new Point(Stage.width, 0));
picBD2.copyPixels(picBD, new Rectangle(pic_mc._width-Stage.width, 0, Stage.width, pic_mc._height), new Point(0, 0));
//初始化位置
pic_mc2._x = pic_mc._x+pic_mc._width-Stage.width;
pic_mc2._y = pic_mc._y;
//计算两个“常量”,以免下面的帧循环中反复计算
var xa:Number = -(pic_mc._width-Stage.width)/2;
var xb:Number = -(pic_mc2._width-Stage.width)/2;
var v:Number =5;//移动速度初值
this.onEnterFrame = function() {
pic_mc._x -= v;
pic_mc2._x -= v;
//判定不同位置下,pic_mc与pic_mc2有左右关系
if (pic_mc._x<xa && pic_mc2._x<pic_mc._x) {
pic_mc2._x = pic_mc._x+pic_mc._width-pic_mc2._width/2;
} else if (pic_mc._x>xa && pic_mc2._x>pic_mc._x) {
pic_mc2._x = pic_mc._x-pic_mc2._width/2;
} else if (pic_mc2._x<xb && pic_mc._x<pic_mc2._x) {
pic_mc._x = pic_mc2._x+pic_mc2._width/2;
} else if (pic_mc2._x>xb && pic_mc._x>pic_mc2._x) {
pic_mc._x = pic_mc2._x-pic_mc._width+pic_mc2._width/2;
}
};
//鼠标移动,修调速度
this.onMouseMove = function() {
v=Math.floor((this._xmouse-Stage.width/2)/30);//30为修调系数
}