用Bitmap/BitmapData 实现人物行走

///main.as

package flash023{

import flash.display.BitmapData;

import flash.geom.Rectangle;

import flash.display.Loader;

import flash.net.URLRequest;

import flash.display.Bitmap;

import flash.events.Event;

import flash.display.Sprite;

import flash.geom.Point;

//import flash023.JPEGMovieClip;

public class Main extends Sprite {

private var loader:Loader;

public function Main():void {

loader=new Loader;

loader.contentLoaderInfo.addEventListener(Event.COMPLETE ,onJPEGLoaderComplete);

try {

loader.load(new URLRequest("mode.jpg"));

} catch (_e:Error) {

trace(_e);

}

}

public function onJPEGLoaderComplete(_evt:Event):void {

var _bmp:Bitmap =_evt.target.content as Bitmap;

var main_bmd:BitmapData = _bmp.bitmapData.clone();

loader.unload();

createBmdArray(main_bmd);

}

public function createBmdArray(_bmd:BitmapData):void{

var posW:uint = _bmd.width / 6;

var posH:uint = _bmd.height / 8;

for (var _h:uint = 0; _h < 2; _h++) {

var _mc:JPEGMovieClip=new JPEGMovieClip;

_mc.x = Math.random()*900;

_mc.y = Math.random()*500;

addChild(_mc);

for (var _w:uint = 0; _w < 6; _w++) {

var _temp:BitmapData = new BitmapData(posW, posH);

var _rec:Rectangle = new Rectangle(1 + _w * posW, _h * posH, posW, posH);

_temp.copyPixels(_bmd,_rec,new Point());

_mc.pushFrame(_temp);

}

}

}

}

}

JPEGMovieClip.as

package flash023{

import flash.display.Bitmap;

import flash.display.BitmapData;

import flash.display.Sprite;

import flash.events.Event;

public class JPEGMovieClip extends Sprite {

private var bmd_array:Array;

private var total:uint;

private var current:uint;

private var bitmap:Bitmap;

private var d:int = 0;

public function JPEGMovieClip() {

this.scaleX = 0.5;

this.scaleY = 0.5;

bmd_array=new Array  ;

total=1;

current=0;

bitmap=new Bitmap;

addChild(bitmap);

addEventListener(Event.ENTER_FRAME,show_func);

}

public function get totalframes():uint {

return total;

}

public function get currentframe():uint {

return current + 1;

}

private function show_func(_evt:Event):void{

d++;

if(d==3){

current%= total;

bitmap.bitmapData=bmd_array[current++];

d = 0;

this.x +=5;

// this.y +=2;

if(this.x > 920){

if(this.y > 560){

this.y = 10;

}

this.x = -10;

}

}

}

public function pushFrame(_bmd:BitmapData):void{

bmd_array.push(_bmd);

total=bmd_array.length;

}

}

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值