Libgdx HTML5 Backend Update

I spent almost a week and a half on the HTML5 backend now and i’m happy to say that i could actually add more than i expected.

New Additions

  • Reflection. Yes, that’s a stupid idea with GWT, but it enables a few things. You can’t use it for your own apps at the moment. Not sure i’ll open up that can of worms. If you are interested in how it works, check out this bozo.
  • Json parsing with reflection. If you read into an ObjectMap things will just work. If you want to deserialize into your own POJOs i’ll have to add something so your POJOs are reflected.
  • The entire scene2d package, including the UI stuff. This was enabled by adding basic Reflection capabilities
  • All of Box2D works now, expect for GearJoint, WheelJoint and RopeJoint. The former two are currently broken in the JBox2D trunk, once those are fixed we have everything apart from RopeJoint.
  • Preferences
  • Fullscreen support
  • Tons of other stuff under the hood that won’t affect you
  • Binary file support, altough i recommend not using it, it’s slow by nature

You can try out most of our tests in HTML5 now. Some box2d tests might be slow due to ShapeRenderer. The box2d simulation itself runs blazingly fast :)

Todo

  • Replace gwt-voices with something else, e.g. a Sound Manager 2 wrapper. I didn’t dig into the gwt-voices sources to much, but for some reason it refuses to work at all in Safari and partially in Firefox. Done, custom wrapper around SoundManager 2, a fantastic API that works perfectly.
  • Fix the backspace button problem so UI textfields work. Done
  • Add a very simple HttpUtils class that allows one to send POST/GET requests to a server. Note that due to the “Same Origin Policy” you’ll be restricted to send requests to the domain your app/game is hosted on.
  • Go through the list of FIXMEs in the source. Done, anything that’s marked as FIXME is either undoable for now, or non-critical.

I’ll most likely not support local files for the time being. Preferences should be sufficient for most games for now.

What Won’t Work

Tilemaps, Audio recorder/device, that’s about it. If i can find a nice Gzip decoder for GWT we can add Tilemaps in as well. Other than that we’ll be pretty much feature complete.

Simple Tutorial

I didn’t have time to write a tutorial on how to port your game yet. Here’s a nice tutorial by Molded Bits on how to get started with the new backend. The markers for files in the assets.txt file are: i -> image, t -> text file, b -> binary file. For now i won’t pack the backend jar with the nightlies as i want things to mature a tiny bit. I’ll follow up with something more in depth that will also show you how you can debug the emitted Javascript easily if necessary.

Ports

Here are a few recent ports.

Pax Britannica by Stefan Wagner.

Mathematiles by Nex

Vector Pinball (see libgdx trunk/demos/)

Gdx invaders (see libgdx trunk/demos/)

10 thoughts on “Libgdx HTML5 Backend Update

  1. Maybe it will help. I’m getting such errors during compilation:

    Compiling module magory.htmlsolitaires.HtmlSolitaires
    Validating newly compiled units
    Ignored 2 units with compilation errors in first pass.
    Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
    [ERROR] An internal compiler exception occurred
    com.google.gwt.dev.jjs.InternalCompilerException: Failed to get JNode
    at com.google.gwt.dev.jjs.impl.TypeMap.get(TypeMap.java:140)
    at com.google.gwt.dev.jjs.impl.TypeMap.get(TypeMap.java:71)
    at com.google.gwt.dev.jjs.impl.BuildTypeMap.getType(BuildTypeMap.java:730)
    at com.google.gwt.dev.jjs.impl.BuildTypeMap.createField(BuildTypeMap.java:570)
    at com.google.gwt.dev.jjs.impl.BuildTypeMap.access$300(BuildTypeMap.java:99)
    at com.google.gwt.dev.jjs.impl.BuildTypeMap$BuildDeclMapVisitor.visit(BuildTypeMap.java:180)
    at org.eclipse.jdt.internal.compiler.ast.FieldDeclaration.traverse(FieldDeclaration.java:285)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1232)
    at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:687)
    at com.google.gwt.dev.jjs.impl.BuildTypeMap.createPeersForNonTypeDecls(BuildTypeMap.java:637)
    at com.google.gwt.dev.jjs.impl.BuildTypeMap.exec(BuildTypeMap.java:514)
    at com.google.gwt.dev.jjs.impl.BuildTypeMap.exec(BuildTypeMap.java:523)
    at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.precompile(JavaToJavaScriptCompiler.java:599)
    at com.google.gwt.dev.jjs.JavaScriptCompiler.precompile(JavaScriptCompiler.java:33)
    at com.google.gwt.dev.Precompile.precompile(Precompile.java:284)
    at com.google.gwt.dev.Precompile.precompile(Precompile.java:233)
    at com.google.gwt.dev.Precompile.precompile(Precompile.java:145)
    at com.google.gwt.dev.Compiler.run(Compiler.java:232)
    at com.google.gwt.dev.Compiler.run(Compiler.java:198)
    at com.google.gwt.dev.Compiler$1.run(Compiler.java:170)
    at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:88)
    at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:82)
    at com.google.gwt.dev.Compiler.main(Compiler.java:177)
    [ERROR] : public class com.badlogic.gdx.scenes.scene2d.ui.Label
    extends com.badlogic.gdx.scenes.scene2d.ui.Widget
    /* fields */
    private final [unresolved] com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds bounds
    private [unresolved] Unresolved type com.badlogic.gdx.graphics.g2d.BitmapFontCache cache
    private [unresolved] int labelAlign
    private [unresolved] float lastPrefHeight
    private [unresolved] com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment lineAlign
    private [unresolved] float prefHeight
    private [unresolved] float prefWidth
    private [unresolved] Unresolved type com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle style
    private [unresolved] java.lang.CharSequence text
    private [unresolved] boolean wrap
    /* methods */
    public void (com.badlogic.gdx.scenes.scene2d.ui.Skin)
    public void (java.lang.CharSequence, com.badlogic.gdx.scenes.scene2d.ui.Skin)
    public void (java.lang.CharSequence, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle)
    public void (java.lang.CharSequence, com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle, java.lang.String)
    public void (java.lang.CharSequence, java.lang.String, com.badlogic.gdx.graphics.Color, com.badlogic.gdx.scenes.scene2d.ui.Skin)
    public void (java.lang.CharSequence, java.lang.String, java.lang.String, com.badlogic.gdx.scenes.scene2d.ui.Skin)
    [unresolved] private void computeBounds()
    [unresolved] public void draw(com.badlogic.gdx.graphics.g2d.SpriteBatch, float)
    [unresolved] public com.badlogic.gdx.graphics.Color getColor()
    [unresolved] public float getPrefHeight()
    [unresolved] public float getPrefWidth()
    [unresolved] public Unresolved type com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle getStyle()
    [unresolved] public java.lang.CharSequence getText()
    [unresolved] public com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds getTextBounds()
    [unresolved] public void layout()
    public void setAlignment(int)
    [unresolved] public void setAlignment(int, int)
    [unresolved] public void setColor(float)
    [unresolved] public void setColor(com.badlogic.gdx.graphics.Color)
    [unresolved] public void setColor(float, float, float, float)
    [unresolved] public void setStyle(Unresolved type com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle)
    public void setText(java.lang.CharSequence)
    [unresolved] public void setWrap(boolean)
    /* members */
    public static class com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle
    extends java.lang.Object
    enclosing type : com.badlogic.gdx.scenes.scene2d.ui.Label
    /* fields */
    public [unresolved] com.badlogic.gdx.graphics.g2d.BitmapFont font
    public [unresolved] com.badlogic.gdx.graphics.Color fontColor
    /* methods */
    [unresolved] public void ()
    public void (com.badlogic.gdx.graphics.g2d.BitmapFont, com.badlogic.gdx.graphics.Color)

    org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding
    [ERROR] at KSGame.java(237): Label congratulations;
    org.eclipse.jdt.internal.compiler.ast.FieldDeclaration

  2. That’s amazing!!
    I’m planning to port something on this new backend, but I have a project with extensive use of RopeJoints, so I was wondering…by any chance, will the problem about RopeJoint support be solvable eventually or it is not feasible at all?

  3. Amazing

    Libgdx just gets better and better every day. Good job on the fast development! Now we just need iOS support and it will be the ultimate game dev lib for any platform.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>