Archive for the ‘OpenFL’ Category

Collisions in OpenFL

Sunday, April 6th, 2014

Fallback or ‘alternate’ content goes here.
This content will only be visible if the SWF fails to load.

To detect if there is a collision among two sprites, it is possible to use the method hitTestObject( DisplayObject ) this way:


if ( moving_left ) {
direction = DIRECTION_LEFT;
x = x - 1;
}

for (child in 1...parent.numChildren ) {
if ( Std.is(parent.getChildAt(child), Wall) ) {
if ( parent.getChildAt(child).hitTestObject (this) ) {
x = x + 1;
}
}
}

Lime.onKeyChange error in version 1.2.2 of openfl-native

Friday, April 4th, 2014

It seems that there is a bug in version 1.2.2 of openfl-native, This is causing a compilation error when compiling for the Android platform and using Linux as a host.
The error is displayed as following.


-compile:
[javac] Compiling 6 source files to /[PATH]/Export/android/bin/bin/classes
[javac] /[PATH]/Export/android/bin/src/org/haxe/lime/MainView.java:381: error: method onKeyChange in class Lime cannot be applied to given types;
[javac] me.HandleResult (Lime.onKeyChange (keyCode, true));
[javac] ^
[javac] required: int,int,boolean
[javac] found: int,boolean
[javac] reason: actual and formal argument lists differ in length
[javac] /[PATH]/Export/android/bin/src/org/haxe/lime/MainView.java:430: error: method onKeyChange in class Lime cannot be applied to given types;
[javac] me.HandleResult (Lime.onKeyChange (keyCode, false));
[javac] ^
[javac] required: int,int,boolean
[javac] found: int,boolean
[javac] reason: actual and formal argument lists differ in length
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] 2 errors

The solution consists on upgrading openfl-native to version 1.3.0:

haxelib update openfl-native

Animations in OpenFL

Saturday, March 15th, 2014

Click on the image and use the arrow keys to control the character.
Fallback or ‘alternate’ content goes here. This content will only be visible if the SWF fails to load.

I am experimenting with OpenFL. Very fast and powerful when developing Flash apps.


import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.Event;
import openfl.Assets;

class Player extends Sprite {

var bitmapArray : Array;

var i : Int= 0;

var moving_up : Bool = false;
var moving_down : Bool = false;
var moving_left : Bool = false;
var moving_right : Bool = false;

public function new () {

super ();
initialize();
}

public function initialize() {
bitmapArray = new Array();

var bitmap : Bitmap = new Bitmap();
bitmap.bitmapData = Assets.getBitmapData ("assets/images/player00.png");
bitmapArray.push(bitmap);
bitmap = new Bitmap();
bitmap.bitmapData = Assets.getBitmapData ("assets/images/player10.png");
bitmapArray.push(bitmap);
bitmap = new Bitmap();
bitmap.bitmapData = Assets.getBitmapData ("assets/images/player11.png");
bitmapArray.push(bitmap);
bitmap = new Bitmap();
bitmap.bitmapData = Assets.getBitmapData ("assets/images/player12.png");
bitmapArray.push(bitmap);
bitmap = new Bitmap();
bitmap.bitmapData = Assets.getBitmapData ("assets/images/player13.png");
bitmapArray.push(bitmap);
bitmap = new Bitmap();
bitmap.bitmapData = Assets.getBitmapData ("assets/images/player14.png");
bitmapArray.push(bitmap);
bitmap = new Bitmap();
bitmap.bitmapData = Assets.getBitmapData ("assets/images/player15.png");
bitmapArray.push(bitmap);
bitmap = new Bitmap();
bitmap.bitmapData = Assets.getBitmapData ("assets/images/player16.png");
bitmapArray.push(bitmap);
bitmap = new Bitmap();
bitmap.bitmapData = Assets.getBitmapData ("assets/images/player17.png");
bitmapArray.push(bitmap);

addChild(bitmapArray[i]);

addEventListener(Event.ENTER_FRAME, onEnterFrame);
}

private function onEnterFrame(evt:Event) {

if ( moving() ) {
removeChild(bitmapArray[i]);

i = (i + 1) % 9;

addChild(bitmapArray[i]);
}

if ( moving_up ) {
y = y - 1;
}

if ( moving_down ) {
y = y + 1;
}

if ( moving_left ) {
x = x - 1;
}

if ( moving_right ) {
x = x + 1;
}
}

public function moving() : Bool {
return (moving_up || moving_down || moving_left || moving_right);
}

public function up() {
moving_up = true;

}

public function down() {
moving_down = true;

}

public function left() {
moving_left = true;

}

public function right() {
moving_right = true;

}

public function stop() {
moving_up = false;
moving_down = false;
moving_left = false;
moving_right = false;
}

}