Archive

Archive for the ‘Library’ Category

AS3 Camera

June 7th, 2009

This is my first go at setting up a reusable camera class so it may need a bit of tweaking when used in a real situation.
Setup a camera, giving it x,y, render window width and height, zoom, a maximum zoom value, and constraints. The camera will then keep the bitmap edges within the render window frame regardless of the zoom (it works out the furthest you can zoom out based on the constraints you give it, but you can make you maximum zoom whatever you like.
This camera class needs to work with a rendering system to support it, which I have in the main class.
I have used my ‘landscape generator‘ code to make the map for this, but it’s very easlily adapted to using a library bitmap.

Download zip

VN:F [1.5.0_759]
Rating: 10.0/10 (2 votes cast)

Library

AS3 Landscape generator

June 6th, 2009

A top down terrain / landscape generator using perlinNoise and paletteMap to create the effect. The gradient that applies the colours can easily be adjusted.
CLICK TO GENERATE NEW IMAGES.

Download zip

Here’s the code …

package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.GradientType;
import flash.display.Shape;
import flash.display.Sprite;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.events.MouseEvent
public class AS3LandscapeGenerator extends Sprite {
public function AS3LandscapeGenerator() {
generatePaletteMap();
bdColor = new BitmapData(320,240,false);
bdNoise = new BitmapData(320,240,false);
var _bmp:Bitmap = new Bitmap(bdColor);
addChild(_bmp);
stage.addEventListener(MouseEvent.CLICK, generate)
generate(null)
}
private var paletteMap:Array;
private var bdColor:BitmapData
private var bdNoise:BitmapData
private function generate(event:MouseEvent):void {
trace(”generate”)
generatePaletteMap();
var seed:int = Math.random() * 30000;
bdColor.perlinNoise(70,70,3,seed,true,true,7,true);
bdColor.paletteMap(bdColor, bdColor.rect, new Point(), paletteMap, [], []);
bdNoise.perlinNoise(2,2,1,seed,true,true,7,true);
bdColor.draw(bdNoise,null,new ColorTransform(1,1,1,.2),BlendMode.OVERLAY);
}
private function generatePaletteMap():void {
paletteMap = [];
var myShape:Shape = new Shape();
var gradientBoxMatrix:Matrix = new Matrix();
gradientBoxMatrix.createGradientBox(256,40,0,0,0);
myShape.graphics.beginGradientFill(GradientType.LINEAR,[0x023175,0x0250C1,0xC7BC96,0x115525,0x725C5A,0x666666,0xFFffff],[1,1,1,1,1,1,1],[0,128,148,157,182,193,218],gradientBoxMatrix);
myShape.graphics.drawRect(0,0,256,10);
myShape.graphics.endFill();
var _bmpData:BitmapData = new BitmapData(256,10,true,0);
var _bit:Bitmap = new Bitmap(_bmpData);
_bmpData.draw(myShape);
_bit.y = 269
for (var n:int = 0;n < 256;n++) {
paletteMap.push(_bmpData.getPixel32(n,0));
}
}

}

}

VN:F [1.5.0_759]
Rating: 0.0/10 (0 votes cast)

Library

AS3 Right Click menu

May 28th, 2009

Very simple post, and I’ve made this very simply, it’s coded on the timeline in this instance, but I should make it into a class.

Download zip

And here’s the code …

stop ();

var MENU_ITEM_0:String=”www.terrypaton.com”;
var MENU_ITEM_1:String=”Made by Terry!”;
var MENU_ITEM_2:String=”LOW Quality”;
var MENU_ITEM_3:String=”HIGH Quality”;

var myContextMenu:ContextMenu;
myContextMenu = new ContextMenu();
addCustomMenuItems ();

function addCustomMenuItems ():void {
myContextMenu.hideBuiltInItems ();
var defaultItems:ContextMenuBuiltInItems=myContextMenu.builtInItems;
defaultItems.print = false;
var item0:ContextMenuItem=new ContextMenuItem(MENU_ITEM_0);
myContextMenu.customItems.push (item0);
var item1:ContextMenuItem=new ContextMenuItem(MENU_ITEM_1);
myContextMenu.customItems.push (item1);
var item2:ContextMenuItem=new ContextMenuItem(MENU_ITEM_2);
myContextMenu.customItems.push (item2);
var item3:ContextMenuItem=new ContextMenuItem(MENU_ITEM_3);
myContextMenu.customItems.push (item3);

item0.addEventListener (ContextMenuEvent.MENU_ITEM_SELECT, menuItemSelectHandler);
item1.addEventListener (ContextMenuEvent.MENU_ITEM_SELECT, menuItemSelectHandler);
item2.addEventListener (ContextMenuEvent.MENU_ITEM_SELECT, menuItemSelectHandler);
item3.addEventListener (ContextMenuEvent.MENU_ITEM_SELECT, menuItemSelectHandler);

contextMenu=myContextMenu;
}
function menuItemSelectHandler (event:ContextMenuEvent):void {
var request:URLRequest;
switch (event.target.caption) {

case MENU_ITEM_0 :
request=new URLRequest(”http://www.soap.com.au”);
navigateToURL (request, “_blank”);
break;
case MENU_ITEM_2 :
trace(”make low”)
//change quality to low
stage.quality=”LOW”;
break;
case MENU_ITEM_3 :
//change quality to high
stage.quality=”HIGH”;
break;
}
}

VN:F [1.5.0_759]
Rating: 1.0/10 (1 vote cast)

Library

AS3 Drop down menu

May 22nd, 2009

A customisable dropdown menu, not the greatest setup, flexible, scrolls and seems to work ok!

Download zip

VN:F [1.5.0_759]
Rating: 0.0/10 (0 votes cast)

Library

AS3 Threshold transition effect

May 20th, 2009

Here’s a simple but effective technique to disolve between images using the bitmapData threshold command. I’ve setup a class that’ll make it easy to apply, but this is really just the start and can be extended and developed quite a bit!

Download zip

VN:F [1.5.0_759]
Rating: 9.3/10 (4 votes cast)

Library

AS3 Draw Landscape

May 16th, 2009

Here’s a small class that I setup to draw a ‘landscape’, well a bunch of wiggly lines at least with a little blurring. Pass a bitmapData and it will draw to it. This could be modified top accept colour parameters and a few other things to make it snazzy.

Download zip

VN:F [1.5.0_759]
Rating: 10.0/10 (1 vote cast)

Library