|
任意度数旋转BitmapData |
|
package com.mygamemylove { /** * 任意度数旋转BitmapData * 正在做一个游戏,把所有游戏素材,最终都绘在下张图上,实现的方法就是合成一些BitmapData对象,在游戏中有时候需要不停的旋转某一个BitmapData * 比如:在飞机游戏中的跟踪导弹,在网上找了很久都没有"任意度数旋转BitmapData"的方法,于是自己写了一个.之前用Matrix这个对象,对BitmapDataR进行旋转操作. * 因为数学学得不好,试了很久,也试不成功,只能做到1到90度的旋转.后来突然想到别外一个巧妙的方法: * 实现原理:用几个嵌套Sprite,构成注册点在图片中心,然后旋转Sprite.再用BitmapData.draw把它的图像画在BitmapData上,获得 * 这个方法的效率可能不是最好,重庆动画制作如果谁有:用Matrix这个对象,对BitmapDataR进行旋转操作,成功的,发一份给我,谢谢. * smallerbird 2010-6-8 * 原创flash教程 尽在自娱自乐 www.MyGameMyLove.com * * 使用方法: * //新建一个对象 * var bdr:BitmapDataRotation=new BitmapDataRotation(BitmapData对象) * //获得某一个旋转度数的BitmapData * bdr.getRotationBitmapData(度数) * * 源码下载地址 http://www.mygamemylove.com/index.php?t=1&id=328 * * */ import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; public class BitmapDataRotation extends Sprite { private var myImg1:Bitmap private var spImg:Sprite private var spImg1:Sprite // private var maxW:Number private var maxH:Number public function BitmapDataRotation(bd:BitmapData) { var myImg:Bitmap=new Bitmap(bd) myImg.x=-myImg.width/2 myImg.y=-myImg.height/2 // spImg=new Sprite(); spImg.addChild(myImg) 重庆影视制作var dd:Number=Math.sqrt(myImg.width*myImg.width+myImg.height*myImg.height)/2 spImg.x=dd spImg.y=dd // spImg1=new Sprite(); spImg1.addChild(spImg) spImg.rotation=45 maxW=spImg1.width maxH=spImg1.height spImg.rotation=0 } // public function getRotationBitmapData(du:Number):BitmapData{ spImg.rotation=du var bd:BitmapData=new BitmapData(maxW,maxH,true,0); bd.draw(spImg1); return bd } } } 本文出自:重庆博得多媒体 |
|
2010-06-27 |
|
 |