as3AStarWithGreenThread

as3AStarWithGreenThread is a A* (A Star) implementation based on a green thread mechanism optimization. The green thread approach allows the lib to schedule chunks of code to run over the time, which avoids a high CPU spike and possible UI hang. The lib works on a grid, which is an instance of the Grid class, that describes the environment. A grid node has a position in space, represented by x, y coordinates, and a boolean indicating if it is walkable.

After a grid is supplied to the lib, developers can query for paths. If a route is found, the lib returns an array containing all nodes that compose the path.

Sample

var _grid :Grid = new Grid(NUM_OF_COLS, NUM_OF_ROWS);

for(var i:int = 0; i < NUM_OF_BLOCK; i++) {
  _grid.setWalkable(posx, posy, Math.random() <= 0.5);
}

_grid.setEndNode(xpos2, ypos2);
_grid.setStartNode(xpos, ypos);

var astar:AStar = new AStar();
var foudd:Boolean = astar.findPath(_grid);

if(found) {
  var _path:Array = astar.path;
}
Comments Off on as3AStarWithGreenThread

Google Analytics

Google Analytics is a native extension to use the Google Analytics API. It was developed using a complete native solution, so it works exactly the same on iOS and Android. Based on a simple API, developers need only a few lines of code to start tracking, having the entirety of Google’s powerful mobile analytics suite available.

The extension provides developers with a significant amount of information, which is extremely useful to gain valuable insight into the path the users take through the game or app. It’s possible to identify problem areas in purchases or gameplay to improve conversions and profits, measure and analyze any user interaction (button clicks, in-game item use, and more), accurately track how long events take in your game (load times, session lengths, and so on). It’s also useful to measure social interactions, demographics such as country of origin, time of day usage peaks, device, and operating system, along with Real time reporting of errors and exceptions in the app.

Sample

public function create(defaultTrackerID:String):GAnalytics;
public function forceDispatchHits():void;
public function getDryRun():Boolean;
public function getOptOut():Boolean;
public function getTracker(trackerId:String):GATracker;
public function isSupported():Boolean;
public function etDryRun(isDryRun:Boolean):void;
public function setOptOut(isOptedOut:Boolean):void;
Commercial
4 Comments

AIR ChromeWindowBlur

AIR-ChromeWindowBlur-ANE is a native extension for Mac/OSX development that uses native graphics to enhance the window SystemChrome option with blur/alpha effects. It overrides some of the properties of AIR Framework and allows Custom Chrome to act as a standard System Chrome, featuring visual blurring and transparency effect powered by Apples Core Graphics API. The blur/alpha effect is a common look and feel for applications in the Yosemit release of Mac OSX.

The extension provides developers with options to control the transparency amount, the blur amount and even the color of the background window. Since it extends Custom Chrome functionality from AIR framework that doesn’t have a title bar, the extension also provides the ability to specify a custom title for the window, alongside other properties like whether or not the window is closable, resizable, maximizable and minimizable.

Sample

// create instance for AIR window Core Graphics awesomeness
var win:NativeWinBlur = new NativeWinBlur();

// set window attributes - always goes before enableWindowBlur()
// ARGUMENTS TO PASS
// hasWindowTitle:Boolean=true,
// windowTitle:String="",
// maximizable:Boolean=true,
// minimizable:Boolean=true,
// closable:Boolean=true,
// resizable:Boolean=true
win.setWindowAttributes(true, "Window title", false, true, true, false);

// set effect properties 
// ARGUMENTS TO PASS
// alpha:Number=0.5, blurAmount:uint=50, red:uint=0, green:uint=0, blue:uint=0
win.enableWindowBlur(0.4, 30, 255, 255, 255);
MIT
Comments Off on AIR ChromeWindowBlur

As3SteeringBehavior

As3SteeringBehavior is a library that provides several steering behaviors algorithms to be used in games. Following the reference of Craig Reynolds, creator of the algorithms, the library has nine behaviors available as interfaces: arrive, avoid, evade, flee, follow path, flock, pursue, seek and wander. Additionally there are some useful classes to help during development, such as Vehicle and Vector2D.

The behaviors can be used out of the box if the SteeringVehicle is instantiated. It describes an entity able to perform steering behaviors, such as a car of an enemy. In order to make the instantiated object perform a behavior, a developer must invoke the corresponding method, such as seek(), every game update. It’s also necessary to invoke the update() method to tell the library to process the behaviors.

Sample

public class FleeTest extends Sprite {
  private var _vehicle:SteeredVehicle;

  public function FleeTest() {
    _vehicle = new SteeredVehicle();
    _vehicle.position = new Vector2D(200, 200);
    _vehicle.edgeBehavior = Vehicle.BOUNCE;
    addChild(_vehicle);

    addEventListener(Event.ENTER_FRAME, onEnterFrame);
  }

  private function onEnterFrame(event:Event):void {
    _vehicle.seek(new Vector2D(mouseX, mouseY));
    _vehicle.update();
  }
}
7 Comments

as3GeomAlgo

as3GeomAlgo is a small collection of geometry algorithms. It contains the implementation of several methods able to create a geometric representation of an image, e.g. fill an image with triangles. This library is useful to be used in a GPU powered workflow.

Among the implemented methods, the library has Marching SquaresRamer-Douglas-PeuckerEar Clipping and Bayazit PolyDecomp. The library is a port of the hxGeomAlgo, the Haxe version which is based on implementations in several different languages.

Sample

var originalBMD :BitmapData = Bitmap(new ASSET()).bitmapData;
var clipRect:Rectangle = originalBMD.rect;
var marchingSquares :MarchingSquares = new MarchingSquares(originalBMD, 1, clipRect);
var perimeter :Vector = marchingSquares.march();
addChild(getTextField("MarchSqrs\n" + perimeter.length + " pts", x, y));
MIT
Comments Off on as3GeomAlgo

Jmulator

Jmulator is a helper library created to facilitate the usage of keyboard emulators (also called keyboard encoders) in ActionScript.  Even though a developer could easily use a keyboard encoder in the Flash and AIR runtimes without this library, the advantages offered by the it are as follows :

  • All keyboard codes dispatched by the board have already been researched for you. To use the library a developer simply create an object matching the board and listen to an event matching the label printed on the board itself;
  • It’s possible to easily enable or disable the OS typematic feature. Typematic mode is when the OS repeatedly sends key down events when a key is being held down;
  • It’s possible to easily listen to only on events, only off events or both on and off events;
  • Listen to one specific input by using the input’s name or to all inputs at once.

Three board models can be used with the library: Ultimarc I-PAC VE, Ultimarc I-PAC (untested) and Ultimarc I-PAC 4 (untested).

Sample

import cc.cote.jmulator.emulators.IpacVe;
import cc.cote.jmulator.events.IpacVeEvent;
 
var emu:IpacVe = new IpacVe(stage);
emu.addEventListener(IpacVeEvent.INPUT_2COIN, test);
 
function test(e:IpacVeEvent):void {
    trace(e);
}
Comments Off on Jmulator

AirPrint

AirPrintANE is a native extension to print bitmapData using iOS Air Print. It has a very minimalist API with two method only, one that allows developers to check if the extension is supported and another to print the bitmapData. In order to use the extension, an instance of the class must be instantiated and the method printBitmapData() must be called.

Sample

var bitmapData:BitmapData = new BitmapData();
var airPrintAne:AirPrintANE = new AirPrintANE ();

if(airPrintAne.isSupported()) {
    airPrintAne.printBitmapData (bitmapData);
}
9 Comments

as3scriptinglib

as3scriptinglib is a library that aims to provide an API for compiling and executing runtime ActionScript/JavaScript within the Flash client (no server required). It uses Adobe’s ECMAScript 4 compiler from the Tamarin project. The library is also able to execute compiled code in the scope of any object and control which classes and functions are exposed to the script domain.

It’s important to note that there are several bugs in Adobe’s compiler that will cause the library to choke on perfectly good script. A Flex app is available for testing and has a few examples included in the left-hand column.

Sample

import com.newgonzo.scripting.ICompiler;
import com.newgonzo.scripting.events.CompilerEvent;
import com.newgonzo.scripting.utils.CompilerLoader;

var loader:CompilerLoader = new CompilerLoader();
loader.addEventListener(CompilerEvent.INIT, compilerInit);
loader.load("ESCompilerSWF.swf");

function compilerInit(event:CompilerEvent):void {
  var compiler:ICompiler = event.compiler;
  compiler.compileAndLoad("trace('Hello World!');");
}
MIT
Comments Off on as3scriptinglib

NativeAndroidLogger

NativeAndroidLogger is native extension that allows applications to send AIR logs to Android LoCat. While developing Android apps, a developer often needs to inspect the logs to find a problem or a bug. The Android LoCat tool is a great solution for that problem, but AIR apps commonly use the trace command to produce logs, which are not displayed in the LoCat flow.

This extension makes the application trace messages able to be viewed by LoCat. It’s also possible to send trace logs with the log levels (debug, error, info etc.) and with tags. As a side effect, the extension helps the application to be compliant with other debug solutions, such as the  TestFairy testing platform logs.

Sample

var bool:Boolean = NativeLoggerANE.getInstance().isSupported();
NativeLoggerANE.getInstance().init(debugModeEnable:Boolean = false, tag:String = "AIR");
NativeLoggerANE.getInstance().debug(message:String);
NativeLoggerANE.getInstance().error(message:String);
NativeLoggerANE.getInstance().info(message:String);
NativeLoggerANE.getInstance().verbose(message:String);
NativeLoggerANE.getInstance().warn(message:String);
Free
Comments Off on NativeAndroidLogger

bullet

bullet-ane is a native extension for the Bullet physics simulation library. It has true native implementations built for iOS (7.0 SDK), iOS Simulator and Android. All other platforms fall back on AwayPhysics, a pure-AS3 implementation of Bullet, meaning the extension will work on all platforms AIR supports. Compared with AwayPhysics, bullet-ane increases performance on mobile apps by an order of magnitude. There is a comparison video available.

The extension is currently written to work with Away3D, but certainly could be made compatible with other Stage3D-based AS3 graphics libraries.

Sample

var _view : View3D = new View3D();
this.addChild(_view);			

// init the physics world
var _physicsWorld : DiscreteDynamicsWorld = new DiscreteDynamicsWorld();

// create ground mesh
var material : ColorMaterial = new ColorMaterial(0x252525);
var mesh:Mesh=new Mesh(new PlaneGeometry(50000*scale, 50000*scale),material);
mesh.mouseEnabled = true;
mesh.addEventListener(MouseEvent3D.MOUSE_UP, onMouseUp);
_view.scene.addChild(mesh);

// create ground shape and rigidbody
var groundShape : StaticPlaneShape = new StaticPlaneShape(new Vector3D(0, 1, 0), 0);
var groundRigidbody : RigidBody = new RigidBody(groundShape, mesh, 0);
_physicsWorld.addRigidBody(groundRigidbody);
8 Comments

Instagram

Instagram-ANE is a native extension to share images on Instagram. The extension works on Android and iOS under the same API and is able to open the Instagram sharing flow to allow user to upload photos to the service. A developer is able to inform three parameters to the extension when triggering the sharing dialog: a BitmapData (the picture to be shared), the image caption and the compression method. By default, the compression is set to JPEGEncoderOptions.

The extension is able to fire events to inform what is happening. It’s possible to monitor if the sharing was performed successfully, for instance.

Sample

var instagram:Instagram = new Instagram();
instagram.addEventListener(InstagramEvent.OK, _instagramEvt);

if (instagram.isInstalled()) {
	instagram.share(new DaVikingCodeLogo().bitmapData, "my caption test");
}

private function _instagramEvt(iEvt:InstagramEvent):void {
	if (iEvt.type == InstagramEvent.OK) {
		trace("shared on instagram");
	}
}
13 Comments

GAF

GAF is an open cross-platform format to store Flash animations for further playback in a multitude of game development frameworks and devices. It enables artists and animators to use Flash CS for creating complex animations and seamlessly use them with various game development frameworks. The GAF Converter analyzes the bytecode of each SWF file and creates a GAF file, which can be played in the desired game framework, such as Starling.

Among the advantages of using GAF is the smaller file size. The traditional animation conversion process generates an image for each frame of the animation thus greatly increasing overall file size. However the GAF animation file stores only unique parts of the animation in a texture atlas and a highly compressed binary config file describing object positions and transformations. GAF also supports 99% of what can be created in Flash so artists and animators don’t need any special planning or preparations of their SWF files before converting. The conversion process involves many optimizations to increase playback performance across all platforms and frameworks, so performance of GAF runtimes is better than that of the Flash player.

Commercial Free
Comments Off on GAF

ZBar

ZBar-ANE is a native extension to recognize QR codes, bar codes and image recognizer. It works for iOS and Android, sharing the same API in both operating systems. The extension has a simple API and is based on events, which are fired when the recognition happens. In order to read any code, the developer must invoke a method passing a bitmap data as its parameter.

Based on the received bitmap data, the extension will analyze its content and dispatch an event. If the image was correctly analyzed and recognized, a successful event containing the code data will be fired. In case the image was not recognized, a fail event is dispatched.

Sample

public function ZBarTest() {
	var imageWithCode :BitmapData;
	var zbar:ZBar = new ZBar();
	zbar.addEventListener(ZBarEvent.FAIL, _zbarEvt);
	zbar.addEventListener(ZBarEvent.SUCCESS, _zbarEvt);

	zbar.init(imageWithCode );
}

private function _zbarEvt(zbEvt:ZBarEvent):void {
	if (zbEvt.type == ZBarEvent.SUCCESS)
		trace(zbEvt.url);
	else
		trace("fail");
}
Comments Off on ZBar

Interactive Debug in Flixel Community

I’ve been working on a new feature called interactive debug that will be available in the next release of Flixel Community. It’s a plugin activated when the debug overlay becomes visible. It allows developers to interactively move and change elements while the game is running. Before showing the new feature in action, let me explain why it was developed.

When making a game, I tend to spend a significant amount of time tweaking things. For instance a level is usually not good at first, because the player is unable to overcome some obstacles (they are too high or their gap is too big). I fix that by following an extremely boring workflow: tweak something, compile, open the game, walk the player’s character to the right place, test, then repeat everything again. I can optimize that workflow by hardwiring the player’s character at the right place, but I just removed a single task from the list. I still need to go back and forth from the IDE to the game to make things right.

Sometimes I just want to test the enemy AI, but the player’s character isn’t at the right spot, or the enemy is at the wrong place, and so on. I got tired of all that and decided to implement something that allow me to change things while the game is running. I call it interactive debug. When it is active, developers can choose tools to change the game elements, e.g. the pointer tools is used to select things, while the tile tool is used to change tilemaps.

Below are some gifs showing my progress related to this feature. This is an early preview and just a few things are implemented, but it’s possible to have an idea of what is coming. The first tool is the Pointer, which can be used to selected elements on the screen. Anything that has a position (x and y properties) can be selected:

Flixel Community - Interactive Debug - Select When an element is selected, it becomes highlighted and its class name is displayed. It’s also possible to select multiple elements by holding Ctrl while clicking:

Flixel Community - Interactive Debug - Multi-selection

After an element is selected, it can be moved using the Move tool:

Flixel Community - Interactive Debug - Move Sometimes it’s useful to remove an element from the screen, so the Eraser tool comes in handy. Just press Delete and all selected elements will be removed from the screen (interactive debug calls kill() on them). It’s also possible to permanently remove elements (from the memory) by pressing Delete while holding Shift:

Flixel Community - Interactive Debug - Delete

Finally the Tile tool allows a developer to modify any tilemap on the screen. Right now it’s possible to edit just the first tilemap found in the state’s display list, but that will change in the future:

Flixel Community - Interactive Debug - Tile tool I have more tools and ideas planned, such as Rotate, a property inspector and the ability to save any changes made during the interactive session. You can follow my progress by watching issue #206 in the Flixel Community repository on Github. I think this new feature will drastically improve the workflow of all Flixel developers.

flixel flixel community gamedev
9 Comments

PNGEncoder2

PNGEncoder2 is a library to compresses BitmapData objects into PNG files stored in ByteArray objects. The code was originally written in the Haxe language, but it is possible to compile it to a SWC file and use it with any AS3 project. The library is highly tuned for speed, outperforming the as3corelib PNGEncoder by up to 5x (on the FAST setting). This is made possible by the custom DEFLATE library written from scratch specifically for this encoder. The custom DEFLATE implementation also allows a developer to choose between compression levels: FAST, NORMAL, GOOD and UNCOMPRESSED.

The library has a true asynchronous encoding that is different from most of the other asynchronous PNG encoders. They usually do the conversion from bitmap data to PNG data asynchronously, then call ByteArray.compress() at the end, which is a long, synchronous operation that can take half the total encoding time or more. As a result, the library has a completely smooth encoding, asynchronously (with progress events) and scales to a target FPS without wasting any cycles idling.

It can also compress large images on-the-fly, since it does the work in manageable chunks (when done asynchronously) instead of all at once. There is no single-step bottleneck. If the BitmapData is not transparent, then it will be automatically encoded using the (generally smaller) 24-bit PNG format, otherwise the 32-bit format is used.

Sample

var bmp : BitmapData = ...;     // The bitmap you want to encode

PNGEncoder2.level = CompressionLevel.FAST;  // Optional. Defaults to FAST

var encoder : PNGEncoder2 = PNGEncoder2.encodeAsync(bmp);
encoder.targetFPS = 12;     // Optional. Defaults to 20. Lower FPSs yield faster compression

// Because the encoder is guaranteed to fire the COMPLETE event
// after at least one frame, it's safe to attach the listener after
// starting the encoding (as long as it's done before the next frame)
encoder.addEventListener(Event.COMPLETE, function (e) {
    var png : ByteArray = encoder.png;

    var bmp2 : BitmapData = ...;
    bmp2 = PNGEncoder2.decode(png);    // Decode the data back to a Bitmap
});

// encoder also dispatches ProgressEvent.PROGRESS events if you
// want to be notified of progress
New BSD
Comments Off on PNGEncoder2