a network of distributed indies

Any community contributions to libgdx go here! Some may get included in the core API when permission is granted.

Re: a network of distributed indies

Postby Wavesonics » Mon Mar 14, 2011 3:26 pm

Outstanding idea, I'll definitely throw my lot in :)
Posts: 102
Joined: Sun Jul 11, 2010 5:10 am

Re: a network of distributed indies

Postby darkfire » Mon Mar 14, 2011 4:51 pm

Its a nice idea. Keep it simple. Don't need another scoreloop etc. I could create something in Rails it could return an html formatted page or an xml/json page depending on the developers preference. Their should be some kind of authentication for submitting apps though.
Follow me @judeibe
Posts: 2
Joined: Mon Mar 14, 2011 4:47 pm

Re: a network of distributed indies

Postby syl » Mon Mar 14, 2011 11:25 pm

Hi there,

so, i made some progress. I do not have much time because I have a full time job, so if you can bring your help is welcome :)

It's currently working (!), just waiting after feedback and i (we ?) will work on better design later.

here is the (functional, but not necessarily pretty, wish help ?) web interface http://www.love-android.net/libGDX-ring/index.php (just click on Login to directly test, or you can also create a login really fast)

here is the java code to use it :

Code: Select all

// AT INIT (where you setup camera or projection)

         // TEST libgdx-ring
         Test test = new Test();
         libgdx_ring_title = test.title;
         libgdx_ring_description = test.description;
         libgdx_ring_image_region = test.image_region;

// IN YOUR RENDERER (where you clear the screen, and generally draw)

      // test libgdx-ring
      // here, if you get relative display, change Gdx.graphics.getWidth() and Gdx.graphics.getHeight() by your values
      int X = Gdx.graphics.getWidth()/2;
      int Y = Gdx.graphics.getHeight()/2;
      // Y wrap
      int y_wrap = Y-(font.getBounds(libgdx_ring_title).height/2);
      font.draw(spriteBatch_aff, libgdx_ring_title, X-(font.getBounds(libgdx_ring_title).width/2), y_wrap);
      font.draw(spriteBatch_aff, libgdx_ring_description, X-(font.getBounds(libgdx_ring_description).width/2), (y_wrap-(int)font.getLineHeight()));
      spriteBatch_aff.draw(libgdx_ring_image_region, X-(libgdx_ring_image_region.getRegionWidth()/2), (y_wrap-(2*(int)font.getLineHeight())-libgdx_ring_image_region.getRegionHeight()), libgdx_ring_image_region.getRegionWidth(), libgdx_ring_image_region.getRegionHeight());

Here is the class code (drop it into your project) (Still, if you can help us beautify...) :

Code: Select all
package com.syl.test43;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class Test extends FileHandle {
   private final String chars_encoding = "UTF-8";
   private String [] xml_rcp_result = new String[5];
   private int real_size_x = 0;
   private int real_size_y = 0;
   // we make image, title and description public in order to obtain them outside this class
   public String title = "";
   public String description = "";
   public ByteArrayInputStream imageStream = null; // really filled in download_image
   private Texture image;
   public TextureRegion image_region;

   // at the new Test() ..
   public Test() {
      // .. we do the xml-rpc request
      xml_rcp_result = XML_RPC_request("http://www.love-android.net/libGDX-ring/xml-rpc-request.php");
      // we fill public fields
      title = xml_rcp_result[0];
      description = xml_rcp_result[1];
      real_size_x = Integer.parseInt(xml_rcp_result[2].trim());
      real_size_y = Integer.parseInt(xml_rcp_result[3].trim());
      // and we download image
      image = new Texture(this); // funny heh ?
      // we set the TextureRegion
      image_region = new TextureRegion (image, 0, 0, real_size_x, real_size_y); // as explained in web interface it's upper left

   // the three methods below overrides FileHandle defaults
   @Override public FileHandle child(String name) {
      // TODO Auto-generated method stub
      return null;
   @Override public FileHandle parent() {
      // TODO Auto-generated method stub
      return null;
   // we override read because it's not a FILE but a downloaded bytebuffer, that doesnt need to be writed on the FS.
   // so when Pixmap or Texture will want that, we will just send the downloaded Stream (thanks Mario) :)
   // thats why this class extends FileHandle (Texture need one)
   @Override public InputStream read() {
      return imageStream;

   /** Method that gives the xml-rpc (only to obtain_a_random_game server-side method) */
   public String[] XML_RPC_request(String server) {
      String [] result = new String [5];
      try {
         URL u = new URL(server);
         URLConnection uc = u.openConnection();
         HttpURLConnection connection = (HttpURLConnection) uc;
         OutputStreamWriter wout = new OutputStreamWriter(connection.getOutputStream(), chars_encoding);
         wout.write("<?xml version=\"1.0\"  encoding=\"" + chars_encoding + "\" ?>\r\n");
         wout.write("  <params>\r\n");
         wout.write("    <param>\r\n");
         wout.write("      <value><string>we_dont_care_what_goes_here_but_could_change</string></value>\r\n");
         wout.write("    </param>\r\n");
         wout.write("  </params>\r\n");
         InputStream in = connection.getInputStream();
         result = read_XML_RPC_Response(in);
      catch (IOException e) {
      return result;

   /** Method that fetches response from XML-RPC (still, specific to obtain_a_random_game server-side) */
   private String [] read_XML_RPC_Response(InputStream in) throws IOException, NumberFormatException, StringIndexOutOfBoundsException {
      StringBuffer sb = new StringBuffer();
      int c;
      while ((c = in.read()) != -1) sb.append((char) c);
      String document = sb.toString();
      String [] result = new String[5];
      String startTag = "<string>";
      String endTag = "</string>";
      int next = 0;
      int nextend = 0;
      // we'll receive 5 strings (title, description, image_URI, real_size_x, and real_size_y)
      for (int i=0; i<5; i++) {
         int start = document.indexOf(startTag, next);
         if (start == -1)
         int end = document.indexOf(endTag, nextend);
         next = start + startTag.length();
         nextend = end + endTag.length();
         result[i] = document.substring(start+startTag.length(), end);
      return result;
   /** Method to download an image, and make a ByteArrayInputStream with that (for FileHandle) */
   public void download_image(String URI) {
      try {
         URL u = new URL(URI);
         URLConnection uc = u.openConnection();
         HttpURLConnection connection = (HttpURLConnection) uc;
         InputStream in = connection.getInputStream();

         ByteArrayOutputStream bytes = new ByteArrayOutputStream();
         byte[] buffer = new byte[256];
         int readBytes = 0;
         while((readBytes = in.read(buffer)) != -1) {
            bytes.write(buffer, 0, readBytes);

         buffer = bytes.toByteArray();
         // here we make the ByteArrayInputStream that will be returned by read() when needed (by Pixmap or Texture)
         imageStream = (ByteArrayInputStream) new ByteArrayInputStream(buffer);


      } catch (IOException e) {


Tomorrow, i think i will write a gdx test, or perhaps someone will have some time to do it ? It will then be easier to test it.

Mario, would you send a A record to my server, or do you want to host it elsewhere ?
Concerning authentication, it's just basic, but I thought possibly to make the openid or google mail, but it's involving domainname http://jeremiahlee.com/blog/2009/09/28/ ... ogle-apps/
So what we do then ? I'm OK to host it, but a domain name would be kewl (i could register it also).

To sum up things, i think i get the full picture, but :
* i need your help in order to get something really kewl and pretty
* i'm waiting after your tests (and patches ?)
* if you want to inspect php source code it's here http://www.love-android.net/libGDX-ring ... ing.tar.gz (i must precise that i'm coding with magic_codes gpc AND runtime..)
* i'm waiting for ideas concerning names, vocabulary (for example i named it libGDX-ring, but tell me)...

I will be back in some hours :)
Posts: 212
Joined: Mon Nov 01, 2010 10:25 pm
Location: Bordeaux, France


Return to Libgdx Contributions

Who is online

Users browsing this forum: No registered users and 1 guest