Created
August 9, 2010 23:09
-
-
Save rboyd/516300 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()"> | |
| <mx:Canvas id="cnv" /> | |
| <mx:Script> | |
| <![CDATA[ | |
| [Embed(source="../assets/spritesheet.png")] | |
| private var Sheet:Class; | |
| private static const FRAME_WIDTH:uint = 65; | |
| private static const FRAME_HEIGHT:uint = 100; | |
| private static const NUM_FRAMES:uint = 3; | |
| private var source:Bitmap; | |
| private var clip:Bitmap; | |
| private var current_frame:uint = 0; | |
| private function update_frame():void { | |
| clip.bitmapData = new BitmapData(FRAME_WIDTH, FRAME_HEIGHT, true, 0); | |
| clip.bitmapData.copyPixels(source.bitmapData, new Rectangle(current_frame * FRAME_WIDTH, 0, FRAME_WIDTH, FRAME_HEIGHT), new Point(0, 0)); | |
| } | |
| private function next_frame(e:Event):void { | |
| current_frame = (current_frame + 1) % NUM_FRAMES; | |
| update_frame(); | |
| } | |
| private function set_timer():void { | |
| var t1:Timer = new Timer(1000); | |
| t1.addEventListener(TimerEvent.TIMER, next_frame); | |
| t1.start(); | |
| } | |
| private function init():void { | |
| source = new Sheet(); | |
| clip = new Bitmap(new BitmapData(FRAME_WIDTH, FRAME_HEIGHT)); | |
| current_frame = 0; | |
| update_frame(); | |
| cnv.rawChildren.addChild(clip); | |
| cnv.invalidateDisplayList(); | |
| set_timer(); | |
| } | |
| ]]> | |
| </mx:Script> | |
| </mx:Application> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment