Archive for the ‘OpenFL’ Category

Colisiones en OpenFL

Sunday, April 6th, 2014

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

Para detectar si hay alguna colisión entre dos sprites se puede usar el método hitTestObject( DisplayObject ) de la siguiente manera:


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 en la version 1.2.2 de openfl-native

Friday, April 4th, 2014

Parece que hay un bug en la version 1.2.2 de openfl-native que causa un error de compilación al compilar en linux para la plataforma Android.
El error es el siguiente.


-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

La solución ha consistido en actualizar la libreria openfl-native a la version 1.3.0

haxelib update openfl-native

Animaciones en OpenFL

Saturday, March 15th, 2014

Click en la imagen y controla al personaje con las teclas de dirección.

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

Estoy haciendo algunos experimentos con OpenFL. Muy rápido y potente a la hora de desarrollar aplicaciones Flash.


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;
}

}