CGArt-中国CGer中的绿色家园
首页 信息动态 原创排行 互动教程 资源千寻 CG人才 CGArt杂志 艺术设计 CG画廊 CG论坛 酷站欣赏 CG搜索 会员中心
Flash Action实现小球沿不规则的路径上移动
来源:闪吧 作者:流浪儿 编辑:浪漫的季节 发布时间:2007年03月14日 16:00:14

用了BitmapData.getPixel();来做的.原理:路径为一像素的纯色的不规则的曲线(如红色),用getPixel();记录曲线上的所有坐标.

import flash.display.BitmapData;
import flash.geom.Point;
var pointArr:Array = [];
var ypos:Number = 200;
var curve:MovieClip = this.createEmptyMovieClip("curve", 10);
with (curve) {
 lineStyle(1, 0xFF0000);
 moveTo(0, ypos);
 for (var i:Number = 0; i<550; i += 6) {
  lineTo(i, ypos+i/10*Math.sin(i/20));
 }
}
var X:Number = curve._width;
var Y:Number = ypos+curve._height;
var copyBitmap:BitmapData = new BitmapData(X, Y, true, 0);
copyBitmap.draw(curve);
var color:Number = Number(0xFF0000);
for (var i:Number = 0; i<X; i += 10) {
 for (var j:Number = 0; j<Y; j++) {
  if (copyBitmap.getPixel(i, j) == color) {
   pointArr.push(new Point(i, j));
   break;
  }
 }
}
copyBitmap.dispose();
var ball:MovieClip = this.createEmptyMovieClip("ball", 20);
with(ball){
 lineStyle(20);
 moveTo(0, 0);
 lineTo(.2, 0);
}
this.onEnterFrame = function() {
 ball._x = pointArr[0].x;
 ball._y = pointArr[0].y-10;
 pointArr.shift();
 if (pointArr.length == 0) {
  delete this.onEnterFrame;
  trace("over");
 }
};
共有评论0条
更多评论..
作者信息 详细信息
评论人:
验证码:
内容:
 
about us advertisement publish conformity service cooperate associate link site map contact us help jump to the top of page