Lime GL best practices/docs/problems?

Hey, I just recently moved down from OpenFL to Lime, but I did so as part of a WebGL independent study, so I’m kinda learning the ins and outs of GL while I figure Lime out. I’ve gotten pretty far on my own, but I have a few questions.

  1. What is the right way to set up the update loop? I tried overriding update in Application and it just didn’t work in the js target (this2 is not defined, iirc), so I resorted to handling all of the game logic in the render function.
  2. What is the right way to get input? I’m assuming overriding onKeyDown/Up/Mouse is the right way to do it, but I also didn’t know about lime.ui.KeyCode until very recently, so I’d figure I’d ask. I had been testing for keycodes via trace()…
  3. On a related note, how do I capture the mouse (for an FPS, for example)?
  4. If you take a look at the game I linked above, the depth buffer isn’t working at all on the js target. I have gl.enable(gl.DEPTH_TEST); gl.depthFunc(gl.LESS); and it works on native even without it. Am I missing something?
  5. I’m always really at a loss whenever I’m trying to find things about Lime. Googling doesn’t even usually get me to the lime docs, and the lime docs are pretty hard to go through, especially when I am usually completely at a loss. Is there a good reference/tutorial/sample project to look at to keep me from coming back to this forum?

Anyway, thanks in advance.

Hi!

  1. It’s designed so that you can override the “update” function and “render” functions to handle game logic and drawing separately. If you override “update” in your subclass and have an error, please let me know and I’ll take a look :smile:

  2. You can override the “onKeyDown” or “onKeyUp” functions on your application class. There are other ways to do it but that’s probably the simplest. Different kinds of input have different signatures. If you don’t get code completion, try this as an example of the methods you can override: https://github.com/openfl/lime/blob/master/lime/app/IModule.hx

  3. By “capture”, do you mean mouse-locking? That isn’t supported yet, but could be simple to add :smile:

  4. Try adding <window depth-buffer="true" /> to your project.xml

  5. I apologize that there aren’t more resources. You can try checking out the “lime-samples” repository, you can clone them similar to OpenFL samples. This helps provide an example of working code, but I do wish to provide more learning resources in the future. If only there were more time in the day!

Wow, really quick response, and from the man himself, no less.
The project.xml fix you suggested fixed that, thank you!
I don’t quite mean mouse-locking, normally FPS games will lock the mouse to the center of the screen, etc. Mouse-locking would be a good feature also though :smile:

I’m overriding update and I get ‘TypeError: this.player is undefined’. I’m running Firefox dev edition on Linux, if that’s important.

class Main extends Application3D {
    var player:Player;
    public override function update(deltaTime)
    {
      player.update();
    }
}

It might be important to note that I don’t override update in the Appliation3D class, which extends from lime.app.Application.

This was running in Lime 2.1.3, and I saw that there was a newer version so I tried updating to 2.2.1. Now, the js build isn’t working for an entirely different reason:
TypeError: (intermediate value)(…) is undefined

I’ll try to find what is causing it. The js output that FF is complaining about:

DefaultAssetLibrary.prototype = $extend(lime.AssetLibrary.prototype,{
    ...
    getText: function(id) {
            var bytes = null;
            var data = ((function($this) { //<--------this line
                var $r;
                var key = $this.path.get(id);
                $r = lime.app.Preloader.loaders.get(key);
                return $r;
            }(this))).data;
            if(typeof(data) == "string") return data; else if(js.Boot.__instanceof(data,lime.utils.ByteArray)) bytes = data; else bytes = null;
            if(bytes != null) {
                bytes.position = 0;
                return bytes.readUTFBytes(bytes.length);
            } else return null;
     }
    ...
});

Okay, so after gutting all of the code, i found that the error shows up as soon as I add this:

class Main extends Application3D {
    public override function init(context:RenderContext)
    {
        super.init(context);
    }
}

Once the super.init(context); line is in the code, Firefox throws that error. The project works fine on the native linux build still, however.

Hmm, that’s strange. Which version of Haxe are you using?

The error with “player” above is that player was null, you’ll need a player = new Player (); call somewhere to instantiate it before player.update can work :slight_smile:

‘Haxe Compiler 3.1.3’

lol, okay maybe I shouldn’t have pasted in a ‘reduced’ form of my code. Changing back to Lime 2.1.3 and building the project works exactly as expected, however, moving player.update() from render() to update() produces the ‘this.player is undefined’.

I tried building the HelloWorld example with 2.2.1 and I got this:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: listen EADDRINUSE
    at errnoException (net.js:904:11)
    at Server._listen2 (net.js:1042:14)
    at listen (net.js:1064:10)
    at net.js:1146:9
    at asyncCallback (dns.js:68:16)
    at Object.onanswer [as oncomplete] (dns.js:121:9)

Now…I have no idea what is going on.
All of my other projects that will build for html5 in 2.1.3 refuse to build in 2.2.1 as well, though they all function fine in native.

Oh, do you have a “lime test html5” command running somewhere? Sounds like the HTTP server is saying the port 3000 is in use

Ah, whoops. Ok, so the HelloWorld example builds and runs just fine.