博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AS3.0 Bitmap类实现图片3D旋转效果
阅读量:6581 次
发布时间:2019-06-24

本文共 3221 字,大约阅读时间需要 10 分钟。

package { import flash.display.Sprite; import flash.display.Loader; import flash.net.URLRequest; import flash.events.Event; import flash.display.Bitmap; import flash.geom.PerspectiveProjection; import flash.geom.Point; import flash.display.Shape; import flash.geom.Matrix; import flash.events.MouseEvent; import flash.display.GradientType;  public class Main extends Sprite {  private var picw:Number = 314;  private var pich:Number = 391;  private var gap:Number = 1.5;  private var speeds:Number = 0.3;  private var maskshape:Shape = new Shape();  private var topcont:Sprite = new Sprite();  private var reftcont:Sprite = new Sprite();  private var sumcont:Sprite = new Sprite();  public function Main():void  {   init();  }  private function init():void  {   var loader:Loader = new Loader();   loader.contentLoaderInfo.addEventListener(Event.COMPLETE,com);   loader.load(new URLRequest("http://files.cnblogs.com/zhoujunfeng2011/Pictures/http_imgloadCA7PGMNR.jpg"));  }  private function com(evt:Event):void  {   var loader:Loader = Loader(evt.target.loader);   var image:Bitmap = Bitmap(loader.content);   var toppic:Bitmap = new Bitmap(image.bitmapData);   var reftpic:Bitmap = new Bitmap(image.bitmapData);   addChild(sumcont);   topcont.addChild(toppic);   toppic.x =  -  picw / 2;   toppic.y =  -  pich / 2;   reftcont.addChild(reftpic);   reftpic.x =  -  picw / 2;   reftpic.y =  -  pich / 2;   reftcont.rotationX = 180;   sumcont.addChild(topcont);   topcont.x = 0;   topcont.y = pich / 2;   topcont.z = 500;   sumcont.addChild(reftcont);   reftcont.x = reftcont.y;   reftcont.y = topcont.y + pich + gap;   reftcont.z = 500;   var pp:PerspectiveProjection = new PerspectiveProjection();   pp.fieldOfView = 55;   pp.projectionCenter = new Point(picw/2,pich/2);   sumcont.transform.perspectiveProjection = pp;   sumcont.x = 400;   sumcont.y = 30;   reftcont.addChild(maskshape);   maskshape.x = reftpic.x;   maskshape.y = reftpic.y;   drawInMask();   reftpic.cacheAsBitmap = true;   maskshape.cacheAsBitmap = true;   reftpic.mask = maskshape;   stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseover);   stage.addEventListener(Event.MOUSE_LEAVE,mouseout);   sumcont.addEventListener(Event.ENTER_FRAME,onFrameHandler);  }  private function drawInMask():void  {   var FillType:String = GradientType.LINEAR;   var mat:Matrix = new Matrix();   var colors:Array = [0xff0000,0xff0000];   var alphas:Array = [0,0.5];   var ratios:Array = [5,255];   mat.createGradientBox(picw,pich,90*(Math.PI/180));   maskshape.graphics.lineStyle();   maskshape.graphics.beginGradientFill(FillType,colors,alphas,ratios,mat);   maskshape.graphics.drawRect(0,0,picw,pich);   maskshape.graphics.endFill();  }  private function mouseover(evt:MouseEvent):void  {   stage.addEventListener(Event.ENTER_FRAME,OnEnter);  }  private function mouseout(evt:Event):void  {   stage.removeEventListener(Event.ENTER_FRAME,OnEnter);   speeds = 0.3;  }  private function OnEnter(evt:Event):void  {   speeds = (this.mouseX - this.stage.stageWidth/2)/40;  }  private function onFrameHandler(evt:Event):void  {   topcont.rotationY +=  speeds;   reftcont.rotationY +=  speeds;  } }}

  

转载于:https://www.cnblogs.com/kangkangblog/archive/2013/01/30/2883442.html

你可能感兴趣的文章
深度学习(二)神经网络中的卷积和反卷积原理
查看>>
Struts2单文件上传原理及示例
查看>>
1015: C语言程序设计教程(第三版)课后习题6.5
查看>>
汽车常识全面介绍 - 刹车系统
查看>>
Perl 教学 Perl5的包和模块
查看>>
售前工程师的成长---一个老员工的经验之谈(三)(转载)
查看>>
网桥 交换机 VLAN 等基本概念---以太网
查看>>
STL - 容器 - Map(一)
查看>>
auguements实参对象的数组化
查看>>
ecshop二次开发常用文件位置
查看>>
Java学习(三)面向对象多线程
查看>>
javascript二维数组排序
查看>>
测试常用的Linux命令总结
查看>>
vue.js个人学习心得
查看>>
CocoaPods的使用
查看>>
POJ2739:Sum of Consecutive Prime Numbers(简单数论)
查看>>
c#和.net区别
查看>>
java的环境变量classpath中加点号 ‘.’ 的作用
查看>>
采用CAN芯片实现和FPGA通信
查看>>
动态规划算法3
查看>>