Posts

Es werden Posts vom Januar, 2011 angezeigt.

Drawing a line after an arrow that follows a path in a Flash MovieClip

If you've ever tried to draw a line after a moving arrow you know what a pain it can be to make it look good. Fed up with my cheap animation skills using masks and tweens I decided to do this using Actionscript 3. Turned out to be super easy with pretty result. Basically you have an MC in which another arrow MC moves along a set path. For example going from left to right along some curves. Now I wanted this arrow to draw a tail behind it: In the first mc set the instance name of the arrow to "arrow" and then use this script: var drawpic:MovieClip = new MovieClip(); addChildAt(drawpic,0); function startFollow():void { drawpic.graphics.lineStyle(5, 0xec008c); drawpic.graphics.moveTo(arrow.x,arrow.y); addEventListener(Event.ENTER_FRAME, followArrow); } function followArrow(e:Event):void { drawpic.graphics.lineStyle(ls, 0xec008c); } function killFollow():void { removeEventListener(Event.ENTER_FRAME, followArrow); } to start drawing, call startFollow function, to end it c...

Dropping Clips on Sprite Graphics V2

Follow-up to last post , here's a whole class that randomly drops MCs onto another using a MovieClip with blue graphics as base on where to throw. You would initialize the class like this: var airRaid:AirRaid = new AirRaid(new LandMass() as MovieClip, spots, "MSpot", 40, 40, 25); airRaid.addEventListener(Event.COMPLETE, doSomething); LandMass() would be your Sprite/MovieClip with the blue landmass. Notice the blue part of your land must have the hex code "cc". spots is a MC in the main class onto which "MSpot" named MCs from library get dropped. drops parameter is the amount of MSpots to be dropped, 40 in example. range would be the area to be left clear around each MSpot interval defines the speed in which to drop each one, in milliseconds. The AirRaid class looks like this: package { import flash.display.MovieClip; import flash.display.BitmapData; import flash.events.Event; import flash.events.EventDispatcher; import flash.events...

Get Graphics Data from world map sprite and add random spots to the land mass.

Task: Randomly drop dots onto the land mass of a world map sprite. How to do it: Transform Sprite into BitmapData and check color values of randomly selected pixel, also check surrounding area for dots too close. // get object from library private var worldland:WorldLand = new WorldLand(); private var landpixels:BitmapData; // make bitmap out of sprite function makeBitmapData():void { landpixels = new BitmapData(worldland.width, worldland.height); landpixels.draw(worldland); } // define dotPoints in order to keep track of space taken by previous dots private var dotPoints:Array = new Array(); // burp function checks random coordinate on map function burp():void { var point:Point = randPos(); while(isWater(point))point=randPos(); //trace("found land: " + point.x + "x" + point.y); var randomDot:Dot = new Dot(); randomDot.x = point.x; randomDot.y = point.y; addChild(randomDot); dotPoints.push(point); } function randPos():Point { return new Point(Math....