Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon Join the GFS Discord Server!
6. November 2011

 

 EDIT: 11/7/2011 Google has published to Maven Central, which makes this entire process obsolete.  Refer to here for new instructions.  Fortunately the new process is much nicer and faster.

PlayN is a wonder piece of technology with a horrible installation process, which is a shame as I think more people should check it out.  So I decided to do something about it, I wrote an installer!

 

I have made the process (almost ) as simple as possible.  For much more detailed process or if you encounter a problem more detailed instructions are available here.

 

 

First download the tools available here.

 

Extract the zip file to any folder ( make sure you extract though, do not run from the zip ) and run Install.cmd.

 

Now it is simply a matter of answering a couple Yes/No questions, and (optionally) point the installer at your JDK folder and telling it where you want PlayN to be installed.  Except the gotcha… read about that below before running the install!

 

 

The Gotcha

 

The only major gotcha is you *must* install the Android 3.0 SDK Platform, and you have to do it in a bit of a hurry, as the SDK install will happen in parallel to the PlayN install which is eventually going to need the Android SDK installed to continue.  I chose to do this because both installs are fairly long and the Android install *should* be completed long before it is needed.  When this screen appears, move quickly! To keep the install quick, click “deselect all” then choose Android 3.0 (API11)->SDK Platform.  You can run the Android SDK Manager again later if you want to add more features.  If for some reason the installer outpaced the Android SDK Manager, simply run the installer again.

 

 

image

 

 

 

**ALSO NOTE**

If you already have the Android SDK installed, this process *may* hijack your ANDROID_HOME environment variable.  When complete, simply change it back if you wish.

 

 

Technical Details

The installer and wizard consist of about 500 lines of Powershell script.  For the record, I have never used Powershell before, so it’s 500 lines of ugly Powershell script! Smile

 

The entire script is documented, so before running you can see exactly what it is going to do, and if it has a problem or you want to install different versions of Maven, Git or the JDK, you can change those URLs right at the top.

 

Over the course of execution, the script:

- downloads and configured the JDK [optional]

- downloads 7zip for later use ( from GameFromScratch.com )

- downloads and installs ( local ) Git

- downloads and runs the Android SDK

- Git’s PlayN from googlecode

- Downloads and installs Maven

- Runs Maven on the PlayN code

- Downloads and installed the New Game Wizard from GFS.com

- Runs the New Game Wizard [optional]

 

 

 

System requirements:

 

Java runtime.  The java sdk will be installed as part of this process, but the java runtime will not.

Powershell 2.0.  Tested on Windows 7 with Powershell 2.0, should work on Windows Server 2008 but untested. *May* work on Vista, untested.  *Should* work on Windows XP, but you will need to download and install Powershell 2.0 first.  Powershell 2.0 ships with Windows 7, and Powershell 1.0 ships with Vista and may require updating using the link above.

 

What files are created?

 

Everything is created under the PlayN installation folder you selected, except a few temp files such as the JDK installer.  These are located in your %TEMP% folder and can be deleted whenever you wanted.

 

How do I uninstall?

 

Simply delete the downloaded scripts.  If you want to erase your PlayN install, first stop adb  ( the Android debugger ).  To do so, load the task manager ( CTRL + SHIFT + ESC ), find adb.exe, right click and end process.  Now simply delete the PlayN folder you created as part of the install.

 

Anything else I need to know?

 

Yeah, the install won’t have touched your Maven or Git configurations if those are already installed, but unfortunately as part of the process we had to update the ANDROID_HOME environment variable.  So if you already have the Android SDK installed on your machine, you will need to update ANDROID_HOME to point to your installed SDK.  This can be accomplished from a command prompt by typing:

    Setx ANDROID_HOME “c:\your\androidsdk\location”

 

 

The new game wizard is installed as part of this process and can be located at [PlayN Folder]\PlayN\NewGame.cmd if you want to create a new game in the future.

 

 

If you want to install more Android SDK features after the install is complete, the Android SDK is located at PlayN\Android\SDK Manager.exe.  Yes, there is a space in the name, and no, I don’t know what the hell Google was thinking when they did that…

 

 

Running Maven after the fact is a bit of a pain in the ass.  I did not set the environment variable as part of the installed ( in case you already had Maven installed I didn’t want to break anything ) so now you have to fully resolve Maven to run it, such as c:\Playn\maven\apache-maven-3.0.3\bin\mvn.bat  [your command]  if you think that gets old in a hurry, you are correct!  The easiest answer is to add the maven Bin directory to your path, such as:

Setx PATH = “%PATH%;c:\playn\maven\apache-maven-3.0.3\bin”

Be careful with the above syntax as you don’t want to screw up your PATH variable.  Try it with a straight SET first ( no X ), then type “SET PATH” to verify it looks correct.  If you are sure it does, run it again using SETX.  At this point you can run Mvn from any directory.

 

 

 

 

IT STILL DOESN’T WORK!!!!

 

 

That’s not really shocking, there are a ton of moving pieces!  Also, I made NO checks to make sure files existed across the network or that your internet connection was up, as both of these would simply be catastrophic failures anyways.  My first suggestion is checking all the URLs at the top of the install script with your browser to make sure they are all still valid and connectivity to each site is fine.  I also have no control over if Google break their build, but if they do, let me know and I can patch the script accordingly.

 

If you have other problems, post them here, email me ( not preferred because others won’t be able to read the results ) or use the PlayN tag on StackOverflow.com and I will monitor there as well.

 

Happy PlayN!

Programming


27. October 2011

 

 

So after running through my earlier Getting Started with PlayN tutorial, I never actually tried running the HTML5 target and today I tried it.

 

 

First task, as a non Java developer was figuring out just how the hell to actually run it.  All of the Google examples seem to use ANT so I went that route.  Unfortunately I didn’t have Ant installed on my machine, which isn’t quite as simple as double clicking an installer EXE.

 

 

First head on over to Ant’s webpage and download the zip.

 

 

Extract the zip file to some folder, I put it in my C route so the path was C:\apache-ant-1.8.2\

 

 

Now you need to add a few environment variables. ( Right click Computer->Properties->Advanced System Settings->Environment Variables )

 

 

First you need to add the ant bin directory ( c:\apache-ant-1.8.2\bin  in my case ) to your already existing PATH variable.  Just add a semicolon to the end append your ant path.

 

Next you need to make sure JAVA_HOME is defined and points to your java SDK root folder.

 

Finally you need to add ANT_HOME, which points to your ant directory ( C:\apache-ant-1.8.2 ) with no trailing slash.

 

 

Now open a new command prompt ( not an existing one, as the settings wont take ) and type ant.  If you are configured correctly you will get an error like:

 

 

image

 

If you get that error, you are off to the races!  Anything else and you probably have a problem somewhere in your install.

 

Now in the command prompt go to the directory you created your game to.  In my case its c:\users\Mike\workspace\MyGame\.  Once there type ant run-html, and if you are anything like me, you are about to get an error message :

Unable to resolve artifact: Missing:
com.googlecode.playn:playn-core:jar:1.0-SNAPSHOT

 

 

So why did this error occur?  Because Eclipse mucked up the Maven install earlier.  Fortunately now that you have ant installed, the fix is quite easy.  In a command prompt, change to the folder you installed Playn to, in my case it was C:\Playn\.  Once there type ant install.  After doing its thing, your maven repository should now be properly configured.  Now go back to your game install folder and type ant run-html again.  Now with everything properly configured, ant will start up a local web server and host your game.  When done, it should look something like this:

 

 

image

 

 

At this point, open up your web browser and go to http://localhost:8080/YourGameName

 

 

And voila, your game running in a browser:

 

image

 

 

 

Easy eh? Winking smile

 

 

Now, dropping to the command line every time you want to run your application is annoying, very annoying.  So how exactly do we run our HTML ( and other ) builds within Eclipse?

 

Open up Eclipse, select the Window menu –> Show View –> Ant

 

The Ant window will now be visible like this:

image

 

 

Click the +Ant icon ( far left ).  A window will pop up like this:

image

 

Select your game ( not the sub projects ) in my case “MyGame”, expand it and select Build.XML and then click OK.

 

Now your game will show up in the Ant view.  Expand it and you will be able to see your various Ant targets:

 

image

 

Right click run-html, select Run As->Ant Build.  Now just like before, open a web browser and navigate to http://localhost:8080/YourGameName/

 

Voila, your game run from inside Eclipse.

Programming


27. October 2011

 

Yeah, I really took my sweet time on this one, but things are better the longer you wait, no? Smile

 

 

In this chapter we get the ball rolling, literally.  Additionally we add collision detection and realistic rebounds.  On the C++ front, we introduce and discuss the various types of casts in C++.

 

For those of you that haven’t read it yet, the Pang C++ Tutorial table of contents is right here.

 

For those that have been following along, Pang Part 7 is here.  As always, full project source is included at the end.

 

 

And here Pang, the worlds most over-engineered pong clone in action!

 

pang7

Programming


13. October 2011

 

*EDIT: 11/06/2011 I wrote an installer that automates this entire process, I recommend checking it out.  Of course, the manual process below will still work.

 

Before you can use PlayN, you need to download and configure it, which is not a completely trivial task. 

 

First of all, you are going to need GIT.  Git is a version control system and if you are working on Windows there are a few ways to go about it.  First is to install Cygwin which is a Linux like environment for Windows.  The other ( and easier ) option is to download it here. ( I used this one ).  Run through the setup, the only option to be aware of is this one:

*EDIT: It was pointed out other Git options such as the EGit plugin for Eclipse exist.

 

image

 

This is the option I used and will assume you will use going forward.  Also I chose windows style line breaks on checkout. Now that Git is installed, its now a matter of downloading the most recent source code from Google.  I assume you have an internet connection, now open a command prompt and change to the directory you want to install PlayN in.  Git will automatically create a “playn” folder, so in my case I used c:\ as the install path.

 

Now type “git clone http://code.google.com/p/playn” and it should look like this:

 

image

 

And after running, it should create a directory called playn whose contents look just like this:

 

image

 

 

If you haven’t already got a Java JDK installed, go get one now.  I started this tutorial off using 7, but truth is Java 6 seems to work better.  So if you don’t already have it, go get it now.

 

Now you need some kind of an IDE.  In this example I am going to use Eclipse, as it seems to be the one that Google most supports.  If you don’t already have Eclipse installed, head on over to Eclipse.org's download section and pick out a version.  In my case I went with Eclipse 3.7.1 Classic x64.  Simple open up the zip file and extract the eclipse folder wherever you want your install to run from.  Run Eclipse.exe and select where ever you want your project files to exist.

 

Now you need to add a couple plugins. 

 

First we need to install the M2E ( Maven ) plugin.  You need to do this inside Eclipse.  In Eclipse, select the Help menu, then Install New Software…

 

In the dialog that pops up pull down the “Works with” box and select “http://download.eclipse.org/releases/indigo/201109230900”.  In a few seconds it will populate a list of options, you want to expand Collaboration and select “m2e – Maven Integration for Eclipse” then click Next, like this:

 

image 

 

Click Next again then agree to the terms and conditions and it will go out, download and configure the Maven integration.  After it is complete it will ask you to restart Eclipse, allow it to.

 

Now we need to add the two Google specific libraries, the Google Eclipse Plugin and the Android Eclipse Plugin.  Both are installed in a very similar manner, just using a different repository.  In Eclipse, select Help->Install New Software.  This time click the “Add…” button and in the “Add Repository” dialog, enter dl.google.com/eclipse/plugin/3.7 like this:

 

image

 

Now click OK and it will again populate the list of selections available.  We need to add another repository for the Android Plugin as well, this repository is located at http://dl-ssl.google.com/android/eclipse/ like such:

 

image

 

Alright, now that those are both added, back in the Install New Software screen, in Works With select our newly created Android repository and select either Android Developer Tools or optionally just select Developer Tools to install everything, which is what I am going to do.  So your screen should look like this:

 

image

 

Finally click Next, Next again, agree to license terms, then Finish.  It will proceed installing the Android tools, you may receive the following warning:

 

image

 

Simply click OK.  Once completed it will ask you to Restart again, choose “Restart Now”.  Now all we need to do is configure the Google Plugin.  Follow the exact same process, Help->Install New Software… and this time in Work With select the Google repository.  I am not specifically sure exactly which plugins and SDKs are required by PlayN, so I simply clicked Select All… disk space is cheap these days right? Smile

 

image

 

Click Next, Next, accept the licensing terms and click Finish.  Now Eclipse is going to do it’s thing… taking a fair bit longer than before.  You may once again receive an “unsigned content” warning, simply click OK again.  And, I bet you saw this one coming… one last request to restart Eclipse.  The last time, I swear!

 

Now that all the tools are created, we need to configure our project.  This is where the m2e plugin we installed earlier comes in.  In Eclipse, in the File Menu select Import.  You should see a list like the following, if the Maven option isn’t there, your m2e install didn’t work properly and try again.  ( Or possibly you didn’t reboot Eclipse earlier? )

 

image

 

You want to select Maven->Existing Maven Projects.  Now for Root Directory you want to navigate to the place Git installed PlayN, in my case c:\playn.  Stupidly you can’t just type the path, you have to hit the Browse button or it won’t well… do whatever it does. Speaking of which, whatever exactly it is doing takes a few minutes.  Many moons later it should look like this:

 

image

 

Click Next, then Finish.  It will in a rage inspiring way that only Java seems capable of, it will appear to reinstall all of the things we just installed then make me a bit of a liar as it asks you to restart Eclipse one more time.  ARGH.  Alright, last time I double promise.

 

Now you have to run the Maven install for playn-archetype.  To do so, switch to the Java Perspective using the Window Menu->Open Perspective->Java Browsing.  On the left hand side should be your Package Explorer with a list of maven projects.  Right click playn-archetype and select Run As –> Maven Install, like this:

 

image

 

 

One the bright side, Eclipse is now fully configured and ready to go.  Now we just create our project!

 

In Eclipse, select File->New->Other...

Now scroll down and select Maven->Maven Project, like this:

 

image

 

 

Click Next, choose your location, I clicked Browse and navigated to my default workspace under my user profile and clicked Next again. In the next screen, check the “Include snapshot archetypes” box, under Filter type “play” then click “com.googlecode.playn”  like such:

 

 

image

 

 

Now click Next.

 

This next screen is again typical Java of making things look way more complex than they really are.  Now you need to provide a groupID and a artifactID, which are bizarro over engineered ways of saying your domain name and game name.  For group id put your domain name ( even a made up one is fine ) in reverse order, for example com.gamefromscratch is what I am using.  Then in ArtifactID put your games name, for example playndemo.  Finally in the properties section gameName will have automatically been created, in the value enter your game name again, like this:

 

 

image

 

Obviously you will want to use different values.  You will see that the packagename is auto-generated based on the values you chose.  Now click Finish.  Not there is a little glitch in Eclipse in that after filling in the value for gameName, you need to click somewhere else on the dialog window to get the Finish button to be enabled.

 

 

Now your Project is created.  If you look in Package Explorer you will now see it ( all 5 of them ).  Here is mine:

 

 

image

 

 

Now it’s a matter of getting things to actually run.  Since we are working on a desktop, lets start with the core ( Java Desktop ) application.  Right click on playndemo-core ( obviously your name will be different ) and choose Run As->Java Application.

 

 

image

 

After selecting Java Application a window will pop up asking you to Select your Java Application.  Scroll down till you find your project it will be named [yourprojname]Java.java like such:

 

 

image

 

 

 

Click it and press OK, and finally the fruit of all our labours!  Our game.

 

 

image

 

 

 

I have to say, that process has to be made MUUUUUUUUUUCCCCCCCHHHHHH simpler if they expect PlayN to catch on.  I mean compared to XNA’s equivalent of downloading and double clicking an EXE, this is simply brutal. Google has a Getting started guide but frankly it assumes a hell of a lot of knowledge of Eclipse, Maven, Git, etc… and still is wrong in some places ( like the Git address ).  Otherwise there is a horrid lack of documentation at this point.

 

 

Well that’s about it, hopefully this guide helped you and if I made a mistake, let me know!

Programming


12. October 2011

Logo

 

Google has released their new open sourced write once run anywhere gaming library, PlayN.  Well if by anywhere you mean Android, Flash, HTML5 or Java that is.  Here is the announcement video:



 

 

In a nutshell, you write your code in Java and it cross compiles to the 4 supported formats.  It’s odd that in the video they announce iOS as one of the platforms that developers need to support ( probably the biggest platform to boot! ) and yet PlayN doesn’t support iOS.  A bit of a headscratcher there!

 

Anyways, I will take a closer look into PlayN and give a review of sorts over the next couple days.

Programming General


See More Tutorials on DevGa.me!

Month List