Showing posts with label PlayN. Show all posts
Showing posts with label PlayN. Show all posts

Tuesday, December 20, 2011

PlayN will not run in Android Emulator :-(

Tried deployed one of the simple game wrote using PlayN and was popped up with this
12-21 03:58:12.579: ERROR/AndroidRuntime(372): FATAL EXCEPTION: GLThread 10
12-21 03:58:12.579: ERROR/AndroidRuntime(372): java.lang.IllegalArgumentException: No configs match configSpec
12-21 03:58:12.579: ERROR/AndroidRuntime(372):     at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:825)
12-21 03:58:12.579: ERROR/AndroidRuntime(372):     at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:981)
12-21 03:58:12.579: ERROR/AndroidRuntime(372):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1326)
12-21 03:58:12.579: ERROR/AndroidRuntime(372):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1180)
12-21 03:58:12.608: WARN/ActivityManager(75):   Force finishing activity com.tmjee.playn.xiangqi.android/.XiangqiActivity
12-21 03:58:12.618: WARN/WindowManager(75): Failure taking screenshot for (216x135) to layer 21030
Oh my god, looks like games written in PlayN cannot be tested in an emulator :-( looks like the emulator is not supporting the necessary OpenGL stuff .... Ouch !!! ....

Monday, December 12, 2011

XHR call results in browser doing an OPTIONS method request

This issue got me bugged for a while, XHR request when inspected in firebug seems to be sending out a HTTP OPTIONS method. If this happened to you, suggest the first thing to check is if the XHR is trying to do a cross-domain request, apparently 127.0.0.1 and localhost are being treated by my firefox as being cross-domain. I always thought cross-domain was not possible with XHR but apparently things changed and it is actually possible now (that's if you have control of the server you are trying to 'cross-domain' to) cause it involves sending bunch of Accept-* headers back. In a nut shell, the browser might sent an HTTP OPTION method request to find out if that piece of resource is allowed to be 'cross-domained'. Googleling gives me the followings

Thursday, November 24, 2011

Little Password Text Widget ... TriplePlay

Hack around a little bit to get a little Password Text Widget from TriplePlay, again crude but works for me ...
public class PasswordField extends Field {
 @Override 
 protected String getLayoutText () {
        String ltext = text.get();
        // we always want non-empty text so that we force ourselves to always have a text layer and
        // sane dimensions even if the text field contains no text
        if (ltext == null || ltext.length() == 0) {
         return " "; 
        }
        StringBuffer r = new StringBuffer();
        for (int a=0; a<ltext.length(); a++) {
         r.append("*");
        }
        return r.toString();
    } 
}

An Image based Text Widget for TriplePlay

Starting to look into PlayN for a bit and whole bunch of utilities build for it like TriplePlay and React. I like the way TriplePlay struture it's widgets. You developed using TriplePlay widgets and it works across platforms without being dependent on the platform's native machinery. Following is a crude way to implement an Text display widget that source it's text from image. Hopefully, TriplePlay will incorporate more of such components into it's distribution. TriplePlay is still young so there're definitely plenty of room for enhancements.

A bit crude but it works.

public abstract class AbstractImageTextWidget<T extends AbstractImageTextWidget<T>> extends TextWidget<T> {
  public AbstractImageTextWidget(String text) {
    this(text, null);
  }
  public AbstractImageTextWidget(String text, Image icon) {
    this.text.update(text);
    if (icon != null)
      setIcon(icon);
  }
  protected void createTextLayer(LayoutData ldata, float tx, float ty, float twidth, float theight, float availWidth, float availHeight) {
    if (twidth > 0 && theight > 0) {
      tlayer = prepareCanvas(_tlayer, twidth, theight);
      char[] textArray = text.get().toCharArray();
      float eachTextWidth = twidth / textArray.length; 
      if (textArray.length > 0) {
        for (int a=0 ; a<textArray.length; a++) {
          Image i = getCharMap().get(Character.toLowerCase(textArray[a]));
          if (i != null) 
            _tlayer.canvas().drawImage(i, a*eachTextWidth, 0f, eachTextWidth, theight);
        }
      }
      tlayer.setTranslation(tx + ldata.halign.offset(twidth, availWidth), ty + ldata.valign.offset(theight, availHeight));
    }
  }
  protected abstract Map<Character, Image> getCharMap();
}