- number sequence generator (range Array generator)
Array comprehension
var x:Array<Int>=[for (i in 0...10) i];// [0,...,9]
x.reverse();// [9,...,0]
// "trace(x.reverse());" create error because reverse():Void return Void
x.reverse(); trace(x); // work done
- 2d Array syntax
var t = [
[1.2,1.2,1.2],
[2.2,2.2,2.2]
];
trace(t);
$type(t); // can't use for compare "if ($type(t) == ".
It will trace the variable type into console,
when "lime build android" etc compile process
type system type interface
var t = [];
t.push([1.2,1.2,1.2]);
t.push([2.2,2.2,2.2]);
trace(t);
var t:Array<Array<Float>> = new Array();
t.push([1.2,2]);
t.push([2,3/2]);
trace(t);
- one line FlxTimer
mytimer.start(3,function(t:FlxTimer):Void{FlxG.switchState(new PS());});
дополнительный синтаксис для таймеров в стороку (не проверено, со слов gama11)
mytimer.start(3,function(t) FlxG.switchState(new PS())) would work too
or mytimer.start(3, t -> FlxG.switchState(new PS())) in haxe 4
- conditional compilation (targeting mobile desktop web ios)
haxeflixel conditionals
compiler conditionals
#if (web || desktop)
//code ...
#elseif android
//code ...
#elseif ios
//code ...
#else
//code ...
#end
- $type | Type.typeof | Types | Reflect
$type show the type only in compiling process. Can't be used to compare data.
$type(x);
Type.typeof can be used to compare data.
var x:Int=1;
var typex:Type.ValueType=Type.ValueType.TInt;
trace(Type.typeof(x)==typex); // -> true
or
import Type.ValueType;
import Type.typeof;
var x:Int=1;
trace(typeof(x)==TInt); // -> true
Type.ValueType. TNull TInt TFloat TBool TObject TFunction TClass(c:Class<Dynamic>) TEnum(e:Enum<Dynamic>) TUnknown
Types
Type groups: Class instance | Enum instance | Structure | Function | Dynamic | Abstract | Monomorph .
Basic types: Bool(true, false) | Int(-1, 0, 1, 0xFF0000) | Float(-1.0, 0.0, 1.0, 1e10) .
numeric operators:
Arithmetic(++ -- + - * / %)
| Comparison(== != < <= > >=)
| Bitwise(~ & | ^ << >> >>>)
| Bool(&& || !)
Reflect isEnumValue isFunction isObject callMethod compare compareMethods
Using Reflect and Type examples of typeof and reflect syntax
- FlxSprite
mysprite.fill(FlxColor.TRANSPARENT);
clear the "var mysprite:FlxSprite" from makeGraphic objects (not checked, from gama11)
- haxeflixel http requests, response, open url, html parser
http requests, response
import haxe.Http;
...
FlxG.log.redirectTraces = true; // trace in debug window of worked app, which can be opened "\" or "F2" keyboard button
var testserver:Bool=true;
var serverlink:String;
if (Main.testserver){serverlink="http://127.0.0.1:8000/myapp/";}
else {serverlink="http://mysite.pythonanywhere.com/myapp/";}
var req:Http = new Http(serverlink);
req.setParameter("appname","ClockworkPlanetPuzzle");
req.setParameter("x","value always string");
req.request( true ); // false=GET, true=POST . DESKTOP WORK DONE ONLY CPP TAGETING. NEKO AND HTML5 IS FALL
trace(req.responseData); // string data. Trace to show data inside vscode "output" tab or app debug window "\" or "F2"
open url
import flixel.FlxG;
...
FlxG.openURL(serverlink,"_blank"); //without "_blank" work too
html parser
Install library use haxelib. Console
haxelib install HtmlParser
"Enter", wait. If all done then next.
Add to haxeflixel "Project.xml" (for example into Libraries section)
<haxelib name="HtmlParser" />
Add to *.hx file
import htmlparser.HtmlParser;
compile once ("Ctrl+Shift+p" for vscode or "lime build cpp -debug" use console from "Project.xml" directory), then can use it with intellisense autocomplete.
- haxeflixel FlxG.save
The calling to FlxG.save, inside Main.hx public function new() method, must be placed/realised only after creating the game object, for example:
_game = new FlxGame(720, 1280, PS, true);
this.usersave_load();
addChild(_game);
or will be raised error "Null object reference", after compiling when app try to run
edit Main.hx for standart haxeflixel project
import flixel.FlxG;
import flixel.util.FlxSave;
class Main extends Sprite
{
public static var x:Float=0;
public static var y:Float=0;
public static var ss:FlxSave;
public static function saveall():Void
{
ss=FlxG.save;
ss.data.x=x;
ss.data.y=y;
ss.flush();
}
public static function loadall():Void
{
ss=FlxG.save;
if(ss.data.x != null){
x=ss.data.x;
y=ss.data.y;
}
}
later, inside PlayState.hx etc, use syntax
Main.saveall(); // to save data
Main.loadall(); // to load data
that delete saved data from windows, find and delete the "appname" folder, for example, placed "C:\Users\user\AppData\Roaming\HaxeFlixel"(that's the location. But only if you left the "company" in project.xml as "HaxeFlixel" in <app></app>).
That erase saved data from code, use "ss.data.x=null;ss.data.y=null;ss.flush();" syntax or use "ss.erase();ss.flush();" (not tested,was some problems with same syntax, look like bug 1302)
- variable sign | if short form | "+=" vs "+ ="
var myvar:Int=0;
var myvarsign:Int=(myvar<0)?-1:1;
myvar+=1; //work good("myvar+ =1;"create error)
- Array slice срез последовательности масива
var x:Array<Int>[1,2,3].slice(1);// -> [2,3]
var x:Array<Int>[1,2,3].slice(-2);// -> [2,3]
- Array move slice сдвинуть срез
var x:Array<Int>=[1,2,3,4,5];
x=x.concat(x.splice(0,2)); // -> x=[3,4,5,1,2]
x=x.splice(3,2).concat(x); // -> x=[1,2,3,4,5]
- Array move element сдвинуть элемент
Using arrays
var x:Array<Int>=[1,2,3,4,5];
x.push(x.splice(0,1)[0]); // -> x=[2,3,4,5,1]
x.push(x.shift()); // -> x=[3,4,5,1,2]
x.unshift(x.splice(4,1)[0]) // -> x=[2,3,4,5,1]
x.insert(0,x.splice(4,1)[0]); // -> x=[1,2,3,4,5]
- for loop
for (i in 0 ... 3) //0 1 2
for (i in [1,3,2]) //1 3 2
- haxeflixel button callback with parameters
var abtn_auto:Array = []; //array for keep buttons, can be good
var ax_auto:Array = [...];
var ay_auto:Array = [...];
var w_auto:Int = 240;
var h_auto:Int = 128;
private function auto_callback(x):Void{ trace(x); }
private function create_auto():Void{
for (i in 0...9){
var b:FlxButton = new FlxButton(ax_auto[i], ay_auto[i], "",function():Void{auto_callback(i);});
b.loadGraphic("assets/images/calc/240128glass_calc_auto.png", false,w_auto,h_auto);
abtn_auto.push(b);
add(abtn_auto[i]);
}
}