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

本文共 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

你可能感兴趣的文章
翻译 | 玩转 React 表单 —— Refs 的运用
查看>>
关于React生命周期的学习
查看>>
从15000个Python开源项目中精选的Top30,Github平均star为3707,赶紧收藏!
查看>>
总奖金 200 万的 AI Challenger 开赛,可申请免费 GPU 资源
查看>>
webpack雪碧图生成
查看>>
搭建智能合约开发环境Remix IDE及使用
查看>>
iOS 12 is coming
查看>>
Blind Return Oriented Programming (BROP) Attack - 攻击原理
查看>>
在xib上removeFromSuperview引用计数问题
查看>>
开源一个企业官网
查看>>
移动端如何做适配?
查看>>
Java反射详细介绍
查看>>
Spring Cloud构建微服务架构—服务消费基础
查看>>
RAC实践采坑指北
查看>>
runtime运行时 isa指针 SEL方法选择器 IMP函数指针 Method方法 runtime消息机制 runtime的使用...
查看>>
PAT A1119 前序遍历后续遍历不唯一生成
查看>>
分布式事务中间件 Fescar—RM 模块源码解读
查看>>
LeetCode36.有效的数独 JavaScript
查看>>
Scrapy基本用法
查看>>
PAT A1030 动态规划
查看>>