惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
IT之家
IT之家
月光博客
月光博客
U
Unit 42
K
Kaspersky official blog
T
Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Engineering at Meta
Engineering at Meta
Recorded Future
Recorded Future
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
P
Palo Alto Networks Blog
爱范儿
爱范儿
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
C
Cisco Blogs
Spread Privacy
Spread Privacy
F
Full Disclosure
博客园 - 聂微东
T
The Blog of Author Tim Ferriss

博客园 - 以天

用DTS从Excel中往SQL SERVER导入数据的问题 - 以天 - 博客园 [AS3]DispatchEvent的古怪问题 FLASH的安全策略,PNG/XML HttpHandle中间的Session的使用 与 web.config中HttpModel 用Eclipse+CDT+MinGW+SVN搭建跨平台的开发环境 - 以天 - 博客园 C++和.net的对象创建 让你的WCF服务支持WebGet属性 - 以天 - 博客园 QC9的安装心得 AS3中的Timer和Event.EnterFrame的区别 XFile中的UV坐标(Panda Xfile导出)的坐标系和3dMax的坐标系不对 [WCF]今天做了一个WCF的测试,测试的结果让我很出乎意料,但百思不得其解啊。 [AS]Sprite的buttonMode带来的问题 [Flash]FMS发布live视频时会出现第一次发布不成功 [Flash]Flash在网页中不能适应用户显示/影藏IE的状态栏时改变舞台大小 [C#]10进制到Excel的26进制的转换函数 [其他]水晶报表中的人民币大写函数 [JS]关于Js文件的导入, [AS3]使用LoadInfo的addEventListener时一定要注意结束时调用removeEventListener 各行业的龙头股 (整理)
[AS3]单个图片进行角色动作化处理【转】
以天 · 2007-07-18 · via 博客园 - 以天

转至:http://www.klstudio.com/post/119.html

  • package {   
  • import flash.display.*;   
  • import flash.net.*;   
  • import flash.utils.Timer;   
  • import flash.events.*;   
  • import flash.geom.*;   
  • public class GameSprite extends Sprite {   
  • private var timer:Timer;   
  • private var sWidth:uint;   
  • private var sHeight:uint;   
  • private var sStep:uint;   
  • private var sDirection:uint;   
  • private var loader:Loader;   
  • private var maps:Array;   
  • private var pointer:uint;   
  • private var map:Bitmap;   
  •         function GameSprite() {   
  • //角色大小;
  •             sWidth = 100;   
  •             sHeight = 100;   
  • //角色移动方向;
  •             sDirection = 0;   
  • //角色步数;
  •             sStep = 1;   
  • //角色动作数组;
  •             maps = new Array();   
  • //初始化角色动作运行指针;
  •             pointer = 0;   
  • //初始化time;
  •             timer = new Timer(100);   
  •             timer.addEventListener(TimerEvent.TIMER, timerHandler);   
  • //图片加载对象;
  •             loader = new Loader();   
  •             loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);   
  •             loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);   
  •             loader.load(new URLRequest("/download/sprite.png"));   
  •             stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);   
  •         }   
  • //错误处理事件;
  • private function errorHandler(event:IOErrorEvent):void {   
  •             trace("IOErrorEvent");   
  •         }   
  • //键盘事件,通过方向键更改角色移动方向;
  • private function keyDownHandler(event:KeyboardEvent):void {   
  • switch (event.keyCode) {   
  • case 40 :   
  •                     sDirection = 0;   
  • break;   
  • case 38 :   
  •                     sDirection = 3;   
  • break;   
  • case 37 :   
  •                     sDirection = 1;   
  • break;   
  • case 39 :   
  •                     sDirection = 2;   
  • break;   
  •             }   
  •         }   
  • //定时器运行事件;
  • private function timerHandler(event:Event):void {   
  • //删除旧的角色动作图像;
  • if (map != null) {   
  •                 removeChild(map);   
  •             }   
  • //显示新的角色动作图像;
  •             map = new Bitmap(maps[sDirection][pointer]);   
  •             addChild(map);   
  • //角色动作循环处理;
  • if (pointer < sStep-1) {   
  •                 pointer ++;   
  •             } else {   
  •                 pointer = 0;   
  •             }   
  •         }   
  • //加载图片完成处理事件;
  • private function completeHandler(event:Event):void {   
  • //根据图片的大小初始化BitmapData;
  • /*
  •              * 注意如果你要保留原来的图片的透明度的话,必将transparent设置为true,同时设置填充色值的前两位为00;
  •              */
  •             var sBmd:BitmapData = new BitmapData(loader.width,loader.height,true,0x00FFFFFF);   
  •             sBmd.draw(loader);   
  • //计算移动步数;
  •             sStep = Math.floor(loader.width/sWidth);   
  • for (var j:uint = 0; j<Math.floor(loader.height/sHeight); j++) {   
  •                 var arr:Array = new Array();   
  • for (var i:uint = 0; i<sStep; i++) {   
  •                     var bmd:BitmapData = new BitmapData(sWidth,sHeight,true,0x00FFFFFF);   
  • //获取单个角色的BitmapData对象;
  •                     bmd.copyPixels(sBmd,new Rectangle(sWidth*i, sHeight*j, sWidth, sHeight),new Point(0,0));   
  •                     arr.push(bmd);   
  •                 }   
  • //放入角色数组里;
  •                 maps.push(arr);   
  •             }   
  • //释放sBmd资源;
  •             sBmd.dispose();   
  • //开始运行角色动作;
  •             timer.start();   
  •         }   
  •     }   
  • }