As an educator and developer I am always looking for new and exciting ways to introduce programming at school. Greenfoot is an excellent tool for simple game development and teaching the basics but what is the next step in terms of games development and expanding a students programming knowledge and experience.
I must admit to having a few problems getting started with PlayN and was getting frustrated that so many of the methods described on their gettingStarted page didn’t seem to work. Eventually, I did seem to find a method that worked which I’ll outline below but for the benefit of anyone following in my footsteps – be patient – at times Eclipse seems to be doing nothing and then it jumps into action.
I installed the Java EE version of Eclipse because it had more downloads and seemed to be the popular version. I didn’t want to be disadvantaged later even though it meant a more complicated set up procedure would follow because the EE Version is not shipped with Maven installed. You MUST follow the instructions below to install Maven and will need to set up for a proxy/firewall if applicable.
- Help > Install New Software
- Select –All Available Websites– from the drop down. This is actually miserably slow so I turned off check all sites for updates or whatever it says and picked Indigo – http://download.eclipse.org/releases/indigo rather than all available sites which speeded the process up no end.
- Search for Maven in the filter box
- Check the box for Maven Integration for Eclipse
- Click Finish to complete the installation
- Select Help → Install New Software…
- In the Work with field enter http://download.jboss.org/jbosstools/updates/m2eclipse-wtp
- Check Maven Integration for WTP
- Click Finish to complete the installation process
Running the PlayN samples
mkdir google cd google git clone https://code.google.com/p/playn-samples
Now they can be imported into Eclipse by:
- Select File → Import from the menu
- Select Maven → Existing Maven Projects and click Next.
- Browse to google/playn-samples
- and the various sample projects will appear in the Projects listing.
- Click Finish to import the projects.
To run the java version – recommended for development:
- Browse down the project explorer to playn-showcase-java
- Right click and select Run as > Java Application
- Select playn-showcase-java from the pop-up and click OK
- The following screenshot is from Pea-Physics.
You can also test the deployment of a game as a deployed HTML version. When I tried this following the instructions given I had errors concerning the GWT Toolkit not being installed but I managed to solve it using the following instructions taken partially from StackOverFlow:
- Right-clicked playn-showcase-html in Package Explorer
- Selected Build Path > Configure Build Path…
- Selected Google > Web Tool Kit from list in left panel
- In GWT SDK box, clicked Use specific SDK, selected only option there, and hit OK.
Once I did this it was able to compile the application and move onto to running it. To run the application you right click on playn-showcase-html and click Run As > Web Application.
Once this has processed you will be given a url similar to http://127.0.0.1:8888/Showcase.html?gwt.codesvr=127.0.0.1:9997 which you can plug into a browser and hence the game/application should run. The documentation suggests removing the ?gwt.codesvr=127.0.0.1:9997 although without this and a further GWT Developers plugin installed this still errors. Clicking on any of the showcase options and it crashes. Additionally, on my Macbook Pro (OSX10.7) where I have MAMP running it gave earlier errors (host not available) – Not Impressed after all this hard work.
Creating a New Project in Eclipse
To create a new project in Eclipse you should create a new project in Maven and specify the appropriate archtype:
- Select File → New → Other from the main menu
- Select Maven → Maven Project in the dialog that appears
- Click Next
- Click Next again unless you wish to specify a custom workspace location.
- Specify com.googlecode.playn in the Filter field
- Select the playn-archetype version 1.1.1 which should be the only one appearing.
- GroupID - this should be a reverse domain for the project
- e.g. net.byteinsight.myproject
- ArtifactID – the name of your game
- e.g. gameone
- Version – The default is 1.0-SNAPSHOT but 1.0, 0.1, r55-alpha would also be suitable.
- Package - As default this is the GroupID + ArtifactID but could be anything
- e.g. net.byteinsight.myproject.gameone
- JavaGameClassName - The name for the classes in your game. Probably as per ArtifactID but starting with capital letter.
- e.g. GameOne
You now have an empty project ready for development.
Now, I went hunting for a tutorial to get me started programming in PlayN (formally known as For Play. Unfortunately, I found this part almost impossible but eventually found some information such as the javadocs and this introductory video from Google I/O 2011