GameMaker > Haxe class

4 posts (showing 1-4)
Panthenol

Market Level 0Community Level 7
579 posts

Quick post here, If like me you had troubles with publishing gameMaker games to FGL

you may find this useful

It's a class to read the "room" files of gameMaker ( level files ) that are made of XML,                                         and convert them into an array of objects

essential parts are done, and you can look into the structure of room files so as to parse the infos you need        

thinking about having less verbose constructors, maybe using dynamic vars,                                          suggestions welcome as usual Smile


[as3]
import haxe.xml.Fast;
import openfl.Assets;

class GameMaker_GMXLoader {    
    
    //---------------------------------------------------------------------------------------------------------------------
    class GM_Instance {
        public function new(x:Int,y:Int,args:String) {
            this.x = x;
            this.y = y;
            this.args = args;
        };
        public var x:Int = 0;
        public var y:Int = 0;
        public var args:String = "";
        public var name:String = "";
    }
    //-------------------------------------------------------------------------------------------------------------------
    class GM_Background {
        public function new(x:Int,y:Int,args:String,visible:Int,htiled:Int,vTiled:Int,hSpeed:Int,vSpeed:Int,Stretch:Int) {
            this.x = x;
            this.y = y;
            this.hTiled = hTiled;
            this.vTiled = vTiled;
            this.args = args;
// etc etc
        };
        public var x:Int = 0;
        public var y:Int = 0;
        public var visible:Int  = 0;
        public var hTiled:Int   = 0;
        public var vTiled:Int   = 0;
public var args:String = "";

    }
    //===================================================================================================================    
    private var objects:Array<GM_Instance>;
    private var backgrounds:Array<GM_Background>;
    private var _xml:Xml;
    private var _fastXml:Fast;
    private var elements:Iterator<Fast>;
    
    //====================================================================================================================    
    public function new() { }
    //=============================================================================================================    
    public function load(fileName:String) {
        objects     = new Array<GM_Instance>();
        backgrounds = new Array<GM_Background>();
        var file:String  = Assets.getText(fileName);
        var xml  = Xml.parse(file);
        var fast = new Fast(xml.firstElement());
        this.elements = fast.elements;    
        
        var cElement:Fast = elements.next();    
        for (e in elements) { parseElement(e); }
    }
    //=============================================================================================================    
    public function parseElement(e:Fast) {
        if (e.name == "instances") { parseInstance(e);};
        if (e.name=="backgrounds") { parseBackground(e); }
    }
    //=============================================================================================================    
    // exemple of background description
    //<background visible="0" foreground="0" name="" x="0" y="0" htiled="-1" vtiled="-1" hspeed="0" vspeed="0" stretch="0"/>
    public function parseBackground(e:Fast) {
        var elements:Iterator<Fast> = e.elements;
        var e:Fast;    
        for (e in elements) {
            var x:String = e.att.resolve("x");
            var y:String = e.att.resolve("y");
            var name:String = e.att.resolve("name");
            var hTiled:String = e.att.resolve("htiled");    
            var vTiled:String = e.att.resolve("htiled");    
            var hSpeed:String = e.att.resolve("hspeed");    
            var vSpeed:String = e.att.resolve("vspeed");
            var stretch:String = e.att.resolve("stretch");
            backgrounds.push(new GM_Background(Std.int(x), Std.int(y), name, 1, 
                             Std.int(hTiled), Std.int(vTiled), Std.int(hSpeed), Std.int(vSpeed),Std.int(stretch));
        }
    }
    //=============================================================================================================    
    // exemple of instance description
    // <instance objName="obj_floor" x="672" y="320" name="inst_69E27C58" locked="0" code="" scaleX="1" scaleY="1" colour="4294967295" rotation="0"/>
    public function parseInstance(e:Fast) {
        var elements:Iterator<Fast> = e.elements;
        var e:Fast;

        for (e in elements) {
            
            var x:String = e.att.resolve("x");
            var y:String = e.att.resolve("y");
            var name:String = e.att.resolve("name");
            var objName:String = e.att.resolve("objName");    
            objects.push(new GM_Instance(Std.int(x), Std.int(y), objName);
            
        }
    }
    
}[/as3]
 [/as3]

I should say i bought gameMaker and it's html5 module, i love the simplicity of the tool, despite it's small flaws and i'm very much looking forward publishing games with gameMaker once some bugs are corrected

posted 2015-04-01T19:59:46-07:00 | edited 2015-04-01T20:14:39-07:00
ozdy

Market Level 6Community Level 13
1482 posts

That's great. Well, I don't use GameMaker, but YellowAfterlife, creator of Bitfive, and contributor to OpenFL and HaXe, will make his Steam game with GameMaker. This should tell you how good GameMaker is! (Or how immature OpenFl is :( )

posted 2015-04-02T13:11:27-07:00 | edited 2015-04-02T13:11:56-07:00
Panthenol

Market Level 0Community Level 7
579 posts

so agreed,  GameMaker needs more love

having used it for a month, i could make a tweet about this tool: 

" time spent on programming is now time spent on making a better game "

being a programming addict, i tend to over-complexify stuff and deliver slowly,                                                      that can be a killer in mobile game dev :(  and GM is just  the perfect remedy to that

( I was able to make my game in less than one week, so really i don't mind the small flaws of the editor )

especially now it's been bought by Playtech,                                                                                            they will really have the ressources to take the tool to the next level,                                         

 http://www.develop-online.net/opinions/playtech-buys-gamemaker-creator-yoyo-games-for-10m/0203202

so i'm looking forward to the next versions :)

posted 2015-04-02T13:29:58-07:00 | edited 2015-04-03T00:55:03-07:00
Kryog

Market Level 0Community Level 1
0 posts

Totally agree, GameMaker is probably the most efficient tool to develop HTML5 games.

The only other solutions are libraries based on hardcore javascript, and a lot of knowledge is required if you want to make an HTML5 game with nice graphics and sound effects for mobile devices.

That being said, javascript libraries are often free and give more control.

posted 2016-03-12T11:15:33-08:00