Disclaimer: I'm new to GWT/PlayN, so this might be an obvious mistake that I'm making.
When I have a basic (starter) PlayN project, my BlahGame
class method implements the Game
interface, which requires three methods: init
, paint
, and update
. The starter class looks something like:
public class BlahGame implements Game {
public void init() { ... }
public void paint(float alpha) { ... }
public void update(float alpha) { ... }
}
I created a BaseGame
class to implement game, like so:
public class BaseGame implements Game {
public void init() { ... }
public void paint(float alpha) { ... }
public void update(float alpha) { ... }
}
My main game class then became a sublass of BaseGame
like so:
public class BlahGame extends BaseGame {
public void init() { ... base.init(); ... }
}
Everything compiles and works from Java. But when I try to GWT-compile the HTML version of my game, I get this error:
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)
...
[ERROR] <no source info>: public class com.deengames.BaseGame
extends java.lang.Object
implements : playn.core.Game
/* methods */
public void <init>()
public void init()
[unresolved] public void paint(float)
[unresolved] public void update(float)
[unresolved] public int updateRate()
I'm not sure what I'm missing here. Is it that some GWT classes need to be updated? Or is it something else? I had expected the HTML vesrion to compile since the Java version compiles; the signatures of the classes shouldn't change from subclassing.
Edit: I'm using a brand new, boilerplate PlayN project. In the class, if I extend the base class AND implement the interface, it still doesn't compile; only removing the base class extension works.
This is your problem right here:
[ERROR] <no source info>: public class com.deengames.BaseGame
You have put code in the top-level package com.deengames
. I bet that your GWT module file is also in that same package directory, probably something like com/deengames/MyGame.gwt.xml
. The GWT module file has to specify sub-package directories for all code that GWT will see.
When you generate a project using the PlayN Maven archetype, it has this structure:
core/src/main/java/com/foozle/core/Barzle.java
core/src/main/java/com/foozle/resources/images/bg.png
html/src/main/java/com/foozle/Barzle.gwt.xml
html/src/main/java/com/foozle/html/BarzleHtml.java
All of the game code is in the com.foozle.core
package and the resources are in the com.foozle.resources
package. If you look at the generated Barzle.gwt.xml
file you will see:
<module rename-to='barzle'>
<inherits name='playn.PlayN'/>
<source path='core'/>
<source path='html'/>
<public path="resources" />
<entry-point class='com.foozle.html.BarzleHtml'/>
</module>
The two <source>
lines explicitly add the com.foozle.core
and com.foozle.html
sub-packages to the GWT project. Anything that is not explicitly listed in this GWT module file will be ignored by GWT. Due to the way GWT specifies these packages, it is not possible to add the top-level package to your GWT project. You cannot use:
<source path=""/>
or:
<source path="."/>
You have to put all of your code in sub-packages that are explicitly enumerated in your GWT module file.
I presume there is an issue with the BlahGame.gwt.xml
file inclusions. Make sure all the directories are included in that file, as sources. The structure should be similar to:
<module rename-to='blah'>
<inherits name='playn.PlayN' />
<source path='core'/>
<source path='common'/>
... etc ...
<source path='html'/>
<public path="resources" />
<entry-point class='full.namespace.BlahGameHtml' />
</module>
Additionally, your BlahGameHtml.java class should look something like:
public class BlahGameHtml extends HtmlGame
{
@Override
public void start()
{
HtmlAssetManager assets = HtmlPlatform.register().assetManager();
assets.setPathPrefix("blah/");
PlayN.run(new BlahGame());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With