flash与动画:图片移动(2)
来源:互联网 发布:p2p软件开发 广州 编辑:程序博客网 时间:2024/05/29 09:21
package {import flash.display.Sprite;import flash.display.BitmapData;import flash.display.Bitmap;import flash.geom.Rectangle;import flash.geom.Point;import flash.events.*;//移动背景的类public class MoveBg extends Sprite{//背景宽度 public var bgWidth:int;//背景高度public var bgHeight:int; //源图像宽度private var sourceBmpWidth:int;//画布private var canvas:BitmapData;private var bitmapData:BitmapData;private var sourceRect:Rectangle;private var pt:Point=new Point();private var bitmap:Bitmap;private var offX:int;private var currentX:int;public function MoveBg(w:int,h:int){this.bgWidth = w;this.bgHeight = h;sourceRect = new Rectangle(0,0,w,h);canvas = new BitmapData(w,h);bitmap = new Bitmap(canvas);addChild(bitmap);}public function start():void{if(!this.hasEventListener(Event.ENTER_FRAME))addEventListener(Event.ENTER_FRAME,onUpdate);}public function stop():void{if(this.hasEventListener(Event.ENTER_FRAME))removeEventListener(Event.ENTER_FRAME,onUpdate);}private function onUpdate(event:Event):void{move();}public function setSource(bitmapData:BitmapData,mouse_Enabled:Boolean=false):void{this.bitmapData = bitmapData;this.mouseEnabled = mouse_Enabled;this.sourceBmpWidth = bitmapData.width;}//移动背景public function move():void{currentX++;offX = currentX % sourceBmpWidth;//偏移的位置if (offX+bgWidth<=sourceBmpWidth){sourceRect.x = offX;sourceRect.width = bgWidth;}else{sourceRect.x = offX;sourceRect.width = sourceBmpWidth - offX; }pt.x = 0;canvas.copyPixels(bitmapData, sourceRect, pt);if (offX >bgWidth){pt.x = sourceBmpWidth - offX;canvas.copyPixels(bitmapData, canvas.rect, pt);}}}}
之前写的一个很小的东西,现在小封装一下,对一些手机图片滚屏效果只是需要用到一张图片来达到循环播放的效果。基本的原理是采取图片裁剪像素的方式来拼凑这图片。目前可以用于一些小游戏开始窗口背景滚屏的效果。
有兴趣可以尝试一下,明天贴一下图片效果。
- flash与动画:图片移动(2)
- flash与动画:图片移动
- flash与动画:AS3图片移动 实现
- flash与动画:图片移动实现新探索
- flash与动画:打字动画(2)
- VC实现图片移动(动画效果)
- flash与动画:打字动画
- flash 与动画:发光
- 树懒_移动开学笔记_day27_网络通信(框架)_动画与图片思路
- 动画-图片的上下移动
- 安卓图片动画移动
- flash与动画:排斥互换
- flash 与动画:轮盘旋转
- flash 与动画:发光实现
- flash与动画:人物动作动画
- 把Flash动画轻松转成GIF图片
- 把Flash动画轻松转成GIF图片
- UIView动画---移动与变形
- 重新开始单片机——AVR下载环境搭建
- STM32 FSMC 总结
- C语言编程 - 清空键盘缓冲区
- zookeeper
- JSP "items" does not support runtime expressions
- flash与动画:图片移动(2)
- 华三ASPF技术白皮书
- 交通银行数据备份系统
- MapReduce 的理解
- 银行数据备份策略
- C++之多态性与虚函数
- C#编程怎么实现Winforms在关闭的时候把线程也一起关闭?
- 银行研发中心数据备份方案解析
- 实现pop push min操作时间复杂度为O(1)的栈结构