PlayN - One code, many platforms

Need programming help? Want to post programming tips? Are you programming a game and want to show it off? That and more here.

PlayN - One code, many platforms

Thumbs up x1

Postby Suyo » March 9th, 2012, 8:39 am

https://developers.google.com/playn/

PlayN is a framework made by Google, and is based on Java. The special thing is that PlayN comes with tools to compile that Java code on 5 different platforms - Java, HTML5, Flash, and if you want to go mobile, Android and iOS. It also has a very simple base code - here's a bouncing ball for you:
Code: Select all
public class MyGame implements Game {
  static final float GRAVITY = 64;

  ImageLayer layer;

  float px, py;
  float x, y;
  float vx, vy;
  float ax, ay;

  public void init() {
    Image img = assetManager().getImage("ball.png");
    layer = graphics().createImageLayer(img);
    graphics().rootLayer().add(layer);

    x = graphics().width() / 2;
    y = graphics().height() / 2;
    ay = GRAVITY;
  }

  public void update(float delta) {
    // Save previous position for interpolation.
    px = x;
    py = y;

    // Update physics.
    delta /= 1000;
    vx += ax * delta;
    vy += ay * delta;
    x += vx * delta;
    y += vy * delta;
  }

  public void paint(float alpha) {
    // Interpolate current position.
    float x = (this.x * alpha) + (px * (1f - alpha));
    float y = (this.y * alpha) + (py * (1f - alpha));

    // Update the layer.
    layer.resetTransform();
    layer.translate(
      x - layer.image().width() / 2,
      y - layer.image().height() / 2
    );
  }

  public int updateRate() {
    // 0 = max framerate
    return 0;
  }
}


Sounds very interesting to me, and the base code seems simple enough. I'll try it, though I heard from some people the documentation sucks. Meh.
Image

Image

Image

Image

Image

Image
User avatar
Suyo
"quite easily the most manly man of all" --Raz

Error contacting Twitter
Error contacting last.fm
 
Posts: 2771
Joined: July 28th, 2009, 2:41 am
Location: Nuremberg (Germany)

Runouw Votes Winner
For winning the RV New Year 2012 Award for Best Moderator. Like you didn't know. XD

Thumbs Up given: 26 times
Thumbs Up received: 359 times

Re: PlayN - One code, many platforms

Postby Jellonator » March 9th, 2012, 12:57 pm

do want.
bepis lmao
User avatar
Jellonator
Code: Awesome

Error contacting Twitter
 
Posts: 342
Joined: August 28th, 2010, 6:25 am
Location: With Waldo.

Thumbs Up given: 18 times
Thumbs Up received: 42 times


Return to Programming