Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

8. March 2013

Version 1.6 of the cross platform Java based game library PlayN was released recently.  PlayN enables you to target desktop, HTML 5, iOS and Android all using a single Java code base. 

 

  

Here are the release notes for this release:

PlayN v1.6

  • The complete API changes are summarized in this JDiff report.
  • Below is a summary of the interesting changes.

Project Layout

  • The way projects are organized has changed, please see Migrating15to16 for details.

Core

  • Implemented tinting for layers (only on GL backends). See Layer.setTint and Layer.tint.
  • Added Log.setMinLevel to allow suppressing log messages below a certain level. (Recommended by Google for Android release builds.)
  • Added Sound.release for releasing audio resources sooner than waiting for GC to do it.
  • Added Assets.getMusic which allows backends to make some optimizations relating to large audio files.
  • Graphics.setSize was removed, and special setSize methods were added to individual platform backend code that can reasonably support them (e.g. HtmlGraphics.setSize).
  • Added GLContext.Stats for debugging rendering performance on GL backends. (See Triple Play's HUD class for an easy way to display these stats.)
  • Deprecated Canvas.setTransform because it interacts poorly with automatic scale factor management in HiDPI modes.
  • Added CanvasImage.snapshot which can be used to create an immutable snapshot of a canvas image which has higher render performance.
  • Added TextLayout.ascent/descent/leading for cases where an app needs to know more about the text that will be rendered by aTextLayout (for underlining, for example).
  • Added Json.Writer.useVerboseFormat to cause the JSON writer to generate pretty printed output (rather than compact, everything on one line output).
  • Added support for nested clipping regions (e.g. clipped groups inside of clipped groups).

Java

  • Made the Java backend look for .wav audio files and then fall back to .mp3. This allows a game to use uncompressed .wav audio files, and only compress them when preparing an Android, iOS, or HTML build.
  • Made playback of large MP3s work (when loaded as music).

HTML

  • Added HtmlAssets.ImageManifest which can be used to pre-load the dimensions of all images known to your app, and enableAssets.getImageSync to (sort of) work in the HTML backend. A wiki article explaining this will be forthcoming.
  • Added support for HiDPI mode. See HtmlPlatform.Config.scaleFactor and HtmlAssets.setAssetScale.
  • Added HtmlGraphics.registerFontMetrics for overriding the (hacky) measurement of font line height.
  • Removed source code from the stock POMs. HTML backends now need to add the source jar files to their html/pom.xml. See playn-samples for an example.

Android

  • Fixed issue with audio not stopping when device was put to sleep.
  • Images loaded locally are now marked as "purgeable" and "input shareable". Google for "android" and those terms to learn more.
  • Added AndroidGraphics.setCanvasScaleFunc which allows games to use lower resolution canvas images if desired. This is useful on devices with low memory.
  • Added AndroidAssets.BitmapOptions which allows games to downsample images if desired. This is useful on devices with low memory.
  • Added GameActivity.prefsName for customizing the name of the Android preferences file.
  • Added GameActivity.logIdent for customizing the Android log identifier. It defaults to playn which is what was hard-coded before.
  • Rewrote sound backend based on SoundPool. Music (large audio files) still relies on the old more-hardware-resource-intensive approach.

iOS

  • Added IOSPlatform.Config for specifying configuration options.
  • Added IOSPlatform.Config.frameInterval for specifying target FPS on iOS.
  • Added IOSImage.toUIImage for custom platform code that needs to manipulate an image loaded via IOSAssets.getImage.
  • Numerous bug fixes and performance improvements.

 

Additionally, TriplePlay 1.6 was also released.  TriplePlay is a library built over top of PlayN to support higher level functionality like UIs and animation.

The following are TriplePlays release notes:

 

TPUI:

  • Added Scroller makeVisible.
  • Added LongPressButton which supports both a normal press interaction and a long-press interaction.
  • Added AxisLayout.Policy CONSTRAIN off-axis sizing policy.
  • Added Field MAXIMUM_INPUT_LENGTH style.
  • Added TableLayout colspan for configuring a column span on an element.
  • Added ValueLabel.
  • Added Style ICON_CUDDLE and UNDERLINE (the latter for underlined text).
  • Added TableLayout.Column free to allow weighting of free columns.

TPAnim:

  • Added AnimGroup for creating a group of invoked-in-parallel of animations that are either added to an Animator later, or are added to a serial animation chain.
  • Moved animation creation methods from Animator to AnimBuilderAnimation then now returns an AnimBuilder which is a cleaner design.
  • Clarified behavior of Animator add and then, made then freak out if used incorrectly.
  • Fixed bugs with repeating animations.

TPSound:

TPParticle:

  • Added Transform randomScale and randomOffset.

TPFlump:

  • Various bug fixes and small API improvements. See API changes.

TPPlatform:

  • Added NativeTextField Validator and Transformer for (native) text validation and transformation.

TPShader:

  • TintingShader was removed as PlayN layers now support tinting directly.

TPUtil:

 

 

For existing PlayN 1.5 developers, there is a guide for migrating to 1.6.

,

17. July 2012

 

Google’s cross platform PlayN game library has just released version 1.4.  PlayN enables you to target desktop, iOS, Android, HTML5 and Flash using a single Java code base.

 

 

Details of this release:

 

 

PlayN 1.4 highlights:


- You can now find out when your Android or iOS game is paused and
resumed via PlayN.LifecycleListener.


- WebSocket support has been added (only works on HTML and Java
backends right now).


- Custom GLSL shaders are now supported on all GL-based backends
(HTML5/WebGL, iOS, Android, Java).


- You can use JavaPlatform for your unit tests without having to wire
up the LWJGL native libraries: use JavaPlatform.registerHeadless.


TriplePlay 1.4 highlights:


- Page turn and (iOS-style) flip transitions that use custom shaders
to achieve real 3D perspective (check out the demo on a WebGL-capable
browser: http://threerings.github.com/tripleplay/widgetdemo.html).


- The long awaited particle system has arrived, break out the
fireworks. This currently only works on GL-based backends, but may
some day work on non-GL backends (less performantly).


- There are a couple of not-yet-finished cool new things:

  • a mechanism for syncing persistent storage across multiple clients
    with conflict resolution (so people can play your games on all their
    devices with the same save game state)
  • a player for our Flash animation exporter
    (https://github.com/threerings/flump), so you can export animations
    from the Flash authoring tool and use them in PlayN games

 

Full release notes available here.

 

I have created a number of getting started guides for PlayN, start here for Eclipse and right here for Netbeans.  Of course, be sure to update the version number in either guide.  Once you get through the install process, it’s a very nice library to work with.

News ,

27. May 2012

 

Quickly following on the release of PlayN 1.3, a new release Playn 1.3.1 has been announced.  There aren’t a lot of changes, mostly just cleaning up the maven integration.  It has absolutely no effect on the NetBeans instructions I posted earlier.  If you are working on an iOS project, I am sure you will appreciate the updated instructions though!

 

Hot on the heels of the 1.3 release, I present the 1.3.1 release! This
patch release contains a few bug fixes, a revamping of the way PlayN
Game projects are organized with Maven, and instructions on how to
build for iOS (made possible by simplifications to the build process
that I got into this patch release)

 

Full release notes available here.

News ,

24. May 2012

 

This tutorial is going to cover everything you need to know to get a PlayN project up and running using NetBeans.  In the end you will know everything you need in order to be able to create and run the Java, Web and Android projects using PlayN 1.3.  The iOS project should work as well, but I am not on a Mac.

 

I have come to a conclusion recently.  I hate Eclipse, every time I work in it, I am fighting with the IDE more than anything else.  More specifically, I hate the M2E maven plugin more than words can describe.  I have attempted to create a series of beginner tutorials for PlayN and each and every time, I end up jumping through a half hour or more of hoops in order to get Eclipse to build my project.  Not much point in making tutorials, if my readers can’t even get PlayN up and running, right?  I don’t want to spend all of my time troubleshooting PlayN installs!  It seems like 90% of the support issues you see with PlayN revolve around Eclipse and M2E problems.

 

So that is what this guide addresses.  It is about getting a specific version of PlayN ( 1.3 ) running with a specific version of NetBeans ( 7.1.2 ), to the point you can run all of the different kinds of targets it supports.  So if you want to get started with PlayN development, start here!  It’s going to look long and daunting, but it really isn’t all that bad, I just go into a lot of detail.  If you’ve already got Netbeans up and running, you can skip 80% of it!

 

 

What you need to get started

 

 

Before we go too far ahead, you are going to need to have downloaded and installed a Java JDK.  Note, the JRE and JDK are different things, and you very much need a JDK installed.  I recommend version 6 over 7 ( that link was to 6 ) at this point, but either *should* work. Additionally, if you are intending to do Android development, you will have to download and configure the Android SDK.  Details on configuring the Android SDK are available here, just ignore all the Eclipse bits.

 

You are now going to need a version of Netbeans.  Here you have a couple of choices:

 

image

 

You want either JavaSE or Jave EE.  If you don’t care about HTML development, go with Java SE, otherwise go with EE.  In this tutorial we are going to go with the Java SE version and add the bits as we need them.  Download and install whichever version you choose now.  Before you install, make sure you have a Java JDK installed already, you will be asked for the JDK path as part of the install process.  Otherwise it’s just a next , I agree, next, I agree, click fest.  Unless of course you are the type that reads EULAs… in which case, see you in a couple hours!

 

 

Configuring NetBeans’ required plugins

 

 

Now that you’ve installed Netbeans, fire it up.  We need to configure a couple plugins right away.  Select Tools->Plugins

image

 

 

In the resulting dialog, select the Available Plugins tab, scroll down and check “Java Web Applications” then click Install.  You can skip this part if you installed Netbeans EE.

 

image

 

Dialog will appear, click Next

 

image

 

Agree to the license agreements and click Install

 

image

 

 

This process will take a few minutes, then request that it restart NetBeans, let it.

 

Now we need to set up the NBAndroid plugin, which is the Netbeans Android connector.  Once again select Tools->Plugins.  This time select Settings in the resulting dialog:

 

image

 

Then click add, and fill in the following in the dialog.  For name enter whatever you want, I went with NBAndroid.  For URL enter http://kenai.com/projects/nbandroid/downloads/download/updatecenter/updates.xml, now click OK.

 

image

 

At this point Android should show up as an option under Available plugins.  For me, as is the way with software, I encountered a bug and it didn’t.  At this point I exited and re-launch NetBeans, go to Tools->Plugins and now the options are there under Available Plugins.  If they don’t show up for you, restart Netbeans.  Now select Android and Android Test Runner for Net Beans 7.x, like so:

 

image

 

Click install, then as before, agree to the EULA and continue. You may run into this scary message, just click continue:

 

image

 

 

All right, Android is now configured, let’s create our project!

 

 

Creating your PlayN project

 

 

Select the File->New Project menu

 

image

 

In the resulting dialog, select the Maven category, then under Projects select “Project from Archetype”. Click Next.

 

image

 

 

In the next screen, on the right hand side click the Add… button

 

image

 

 

Fill the next dialog in with the following details; Group Id = com.googlecode.playn Artifact Id= playn-archetype Version 1.3, then click OK.

 

image

 

Now make sure your newly added Archetype is selected and click Next.

 

image

 

 

Now fill in the following details.  Name your project in ProjectName, I am going with playndemo and assume you did too for the rest of this tutorial.  Artifact Id will be set automatically.  Group id is your url, in my case com.gamefromscratch.  Be sure to specify 1.3, it will start as 1.0-SNAPSHOT, you don’t want this!  Finally, and this part is extremely important, fill in the value for JavaGameClassName!  I went with playndemo, but it is extremely important to click somewhere on the screen after setting it, another text box for example, or the setting will not be saved!!!  If you get an error later on that JavaGameClassName was not set, you ran into the bug of this value not saving. Now click Finish.

 

image

 

 

If all went well, it should have generated your project like this:

 

image

 

 

Building your project ( resolve Maven dependencies )

 

 

This next part is incredibly important, we need Maven to bring in all the various dependencies.  Right click the Meta Project and select Clean and Build.

 

image

 

Maven is now going to download and configure all of the various dependencies, and there are a lot of them.  Like tea?  Perhaps now would be a good time to brew a cup.  Just keep an eye on the bottom right of your screen:

 

image

 

 

Ideally what you want to see is this:

 

image

 

Fortunately, you only need to do that part once.  If you are sitting there thinking… wow, this really took a long time, I wonder if something went wrong?!?!?!  Nope, nothing went wrong, it really does take that long!  Welcome to maven.

 

Running the Desktop Java app

 

Normally all you would have to do is right click the Java project and choose run.  However as of right now there is a dependency on the LWJGL native dlls that you need to resolve manually. If you are reading this at some point in the future, you may no longer need to perform this step!

 

Try running the Java App.  Right click playndemo Java and select Run

 

image

 

In the resulting dialog, select your main class if required and click Select Main Class.

 

image

 

You will receive:

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:exec (default-cli) on project playndemo-java: Command execution failed. Process exited with an error: 1(Exit value: 1) -> [Help 1]

 

If you scroll up the error, you will see:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1738)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1028)
    at org.lwjgl.Sys$1.run(Sys.java:73)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
    at org.lwjgl.Sys.loadLibrary(Sys.java:95)
    at org.lwjgl.Sys.<clinit>(Sys.java:112)
    at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
    at playn.java.JavaGLContext.viewWasResized(JavaGLContext.java:125)
    at playn.core.gl.GLContext.setSize(GLContext.java:48)

 

This is because of the missing libraries, lets add those now.  ( Or if you didn’t, this problem is fixed and skip ahead! )

 

Head on over to LWJGL’s download site and download the binaries zip.  Now extract the contents of this file somewhere, it doesn’t really matter where.  I extracted to c:\temp, preserving folder names.  The end results looked like this:

 

image

 

It’s really only the native folder we care about.  Stick it anywhere, just remember the path.

 

Now back in NetBeans, right click playndemo Java and select Properties.

 

image

 

 

We now have to add a VM param to the Run options.  On the categories side, select Run, then on the right in VM options, add  -Djava.library.path=c:\path\to\lwjgwl\windows, like this:

 

image

 

Click OK, then right click the Java project and select Run.

 

image

 

Voila, your running Java PlayN application.  Now on the the HTML project.

 

Running the PlayN HTML application

 

Right click playndemo HTML and choose Run:

 

image

 

If Run isn’t an option, something went wrong when you configured the Java Webserver plugin, or you aren’t running EE edition.  Go back and repeat that step until run appears.

 

On first run ( assuming you didn’t install a webserver as part of your Netbeans install ), you will encounter this dialog with an empty server list:

 

image

 

 

We now need to install and configure a web server, don’t worry, its an easy process.  In the menu, select Tools->Servers

 

image

 

In the resulting dialog, click Add Server…

 

image

 

Click GlassFish Server 3+, then Next

 

image

 

Save it wherever you want, I went with the defaults, click Finish ( unless you want to change default settings ):

 

image

 

If all went well, you should see the following screen, simply click Close.

 

image

 

Now right click playndemo HTML and choose run. Now in the deployment dialog, you have a server you can select, do so and click OK:

 

image

 

And voila, your app running in a browser:

 

image

 

If you have problems or need to maintain or restart your GlassFish install, you can do so via the Window->Services menu option:

image

 

 

Running your PlayN Android Application in Netbeans

 

This part has a bit of a gotcha attached.  PlayN switched to use OpenGL 2.0 and the Android emulator simply doesn’t support Open GL 2.0 yet.  You can try to run it on the emulator, but it will crash every time.  If you have a physical device, you can get Netbeans to target it.

 

First right click playndemo and select Properties:

image

 

On the left hand side selection Actions.  In the Actions list, select Run Project.  Under Execute Goals: enter android:deploy android:run, and under Set Properties: enter skipTests=True and android.device=usb.  Finally click OK.  This is behind the scenes configuring a pair of maven commands.

 

image

 

Now with your Android phone plugged in, with USB debugging enabled, right click playndemo and choose Run.  Oddly enough, sometimes it deploys and runs the application, sometimes it simply deploys it and fails to run.  Worst case scenario, locate the app icon on your device and launch it manually.

 

Voila, PlayN running on my Galaxy Note  ( the black is because of the 1280x720 resolution ):

 

export_12

 

 

As you can see, you can successfully target all three platforms from Netbeans.  Trust me, that process looked a lot more complicated than it actually was.  Plus, you only have to do 95% of it once.

Programming , ,

23. May 2012

 

The developers over at Google have announced PlayN release 1.3!  Ok, I’m a bit late to theplayn-logo party, as they actually announced it two days ago, but hey… it was a holiday here in Canada, so I was allowed to be asleep at the wheel on this one! Winking smile

 

So, what have we got to look forward to in the 1.3 release?

 

 

- The Java backend has been rewritten to use LWJGL instead of Java2D.
This makes the Java backend behave more like the other OpenGL
backends, and allows one to write and test code that uses the GL20
(direct-to-OpenGL) abstraction on the desktop, just as one does for
the 2D PlayN APIs.

- HiDPI (aka Retina) support is implemented for the Java, iOS and
Android backends. Eventually we can probably make it work in the HTML
backend as well for games that wish to use HiDPI images for their web
incarnation. I will write an article explaining HiDPI support and how
to use it in the not wildly distant future.

Note that the Java backend now requires LWJGL's native libraries. The
new archetype contains the necessary changes to the POM to cause Maven
to automatically unpack and use the native libraries. I'll also update
the samples with the same changes. Please make these same changes to
your project's java/pom.xml when you upgrade to PlayN 1.3. Eclipse
users will probably need additional machinations, which can hopefully
be detailed by someone who has been using Eclipse with 1.3-SNAPSHOT
for the last month or so.

 

You can get the full details in the release notes.

 

To go along with PlayN’s 1.3 release, TriplePlay also has announced a 1.3 release.  TriplePlay is, in their own words:

Triple Play is a collection of game-related utility classes that can be used with the PlayN library on all of its myriad platform targets.

 

Basically it adds a heap of great functionality on top of PlayN, likes GUIs, animation controllers, etc…  The lead developer of TriplePlay, Michael Bayne, is probably the most unsung hero of the PlayN development, and is easily the most active developer outside of Google ( or perhaps, over all? ) and deserves kudos for his efforts.

 

TriplePlay 1.3 details are in the release notes.

 

 

 

To get up and running, follow these instructions.  Note, you need to set the version to 1.3 instead of the values mentioned in the tutorial.

 

EDIT: Big warning however!  The current build requires LWJGL native libraries or it will break.  They are in the process of making this part less… broken, but for now it simply won’t work unless you handle this dependency manually.

News ,

Month List

Popular Comments