Flash and game notes: Rolling numbers

Source: Internet
Author: User

 

The game requires a lot of Bitmap text to increase the appearance. Recently, I also tried a simple experiment version. One of the ideas is to use the tweenlite endarray to refresh the bitmap and try to scroll through the number.

The basic class used is bitmap. The simplest and most direct method is to copy the pixel value.

The following is a simple experiment. You can try this simple effect.

 

package{import flash.display.Sprite;import com.greensock.TweenLite;import com.greensock.plugins.TweenPlugin; import com.greensock.plugins.EndArrayPlugin; import flash.events.MouseEvent;public class Main extends Sprite{private var rollText:RollTextField;public function Main(){TweenPlugin.activate([EndArrayPlugin]);rollText=new RollTextField();addChild(rollText);rollText.x=200;rollText.y=200;rollText.init(new nums(0,0),10);stage.addEventListener(MouseEvent.CLICK,onClick);}private function onClick(event:MouseEvent):void{rollText.text=Math.random()*5000;}}}

We can prepare numbers for the experiment materials. We need to divide the materials evenly so that each number can be averaged during cropping.

 

 

After making the video, preview it in Flash cc. You can prepare a digital clip for cropping and previewing at will.

 

package {import flash.display.Bitmap;import flash.display.BitmapData;import flash.display.Sprite;import flash.geom.Point;import flash.geom.Rectangle;import flash.text.TextField;    import com.greensock.TweenLite;  public class RollTextField extends Bitmap{private var source:BitmapData;private var w:int;private var h:int;private var rect:Rectangle;private var pt:Point;private var copyImg:BitmapData;private var curValue:int = 0;private var offX:int = 0;public var endFun:Function;public function RollTextField(){}public function init(source:BitmapData,len:int,offX:int=0):void{this.source = source;this.offX = offX;w = source.width / len;h = source.height;}public function set text(value:int):void{if (! source || value == curValue){return;}var myArray:Array = [curValue];this.curValue = value;if (! rect){rect = new Rectangle(0,0,w,h);}if (! pt){pt=new Point();}TweenLite.to(myArray, 1, {endArray:[value],onUpdate:onUpdateView,onComplete:onComplete});function onUpdateView():void{var myNewStr:String = String(int(myArray[0]));var len:int = myNewStr.length;if (copyImg){copyImg.dispose();copyImg = null;}copyImg =new BitmapData(len*w,h,true,0x0);for (var i:int=0; i<len; i++){var num:int = int(myNewStr.charAt(i)) + offX;rect.x = num * w;rect.y = 0;rect.width = w;rect.height = h;pt.x = i * w;pt.y = 0;copyImg.copyPixels(source,rect,pt);}bitmapData = copyImg;}function onComplete():void{if (endFun!=null){endFun.apply(null,null);}}}}}

 

Note: Recently, csdn images have been uploaded with watermarks, so I really want to try this boring setting.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.