Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon
5. March 2014

 

If you’ve been a regular reader of my blog you will probably know that I am not Eclipse’s biggest cheerleader.  “I hate it” might be a bit strong, but not by much.  Recently though, I’ve been forced to use it more and more.  Frankly, if you want to work in cross platform Java, especially using Google’s tools, you are pretty much forced to these days.  One of my biggest annoyances is the obtuseness of the interface.  Today I am going to show one such example.

 

One of the things about working with LibGDX in Eclipse is it uses a fair number of threads and when an exception is thrown, if it wasn’t directly in your code, you are kinda screwed.  Look at this example, from code I am currently working on:

 

image

 

What I see here is I caught a “Throwable” derived exception and am throwing a RuntimeException in turn.  I can look up in the thread stack trace to see where it was thrown ( although the code above makes it pretty obvious, but stay with me for a moment).

 

If I look at the debug window, I can see that stack trace, to see where the exception came from:

image

 

There is a really useful piece of information here ( the exception type was GdxRuntimeException ), but the stack trace itself is pretty flat.  That is because each stack is thread specific and frankly, we just created this thread.  So our stack basically consists of Thread.run() and well, that’s about it.  We can tell by our code that the exception was thrown somewhere in LwjglApplication.mainLoop() but that is all we’ve got to work with.  We could set a breakpoint in mainLoop and run until it triggers, but that is extremely annoying.  What we want to do instead is stop execution when the exception is THROWN, not when it is caught.

 

This can be done in Eclipse, but in the way of Eclipse, it certainly isn’t intuitive.  Since we know our exception type is GdxRuntimeException, we will trigger it to stop execution whenever one of those is thrown.  Let’s look at how.

 

In Eclipse, switch to Debug Perspective.

image

 

Now locate the Breakpoint panel and the J! icon.  ( Intuitive eh? )

image

 

In the resulting dialog, in the Choose an exception text field, enter GdxRu*.  The asterisk is a wildcard, so it will return any Exception that start with GdxRu.  Click OK.

image

 

By the way, the default is *Exception*, meaning breakpoint on all Exceptions with the word Exception in them.  That sounds wonderful and all, problem is, it simply doesn’t work… yay Eclipse.  There is probably some 5 year old bug report somewhere explaining why.

OK, bitching aside, your exception list should now contain an entry for GdxRuntimeException:

image

 

Now right click the Exception and select Breakpoint Properties…

image

 

Make sure the following settings are enabled:

image

 

Now when you run the code again, the debugger will stop where the exception is thrown.

image

Wahoo!  Now that information is about 1000x more useful.  Now we see where our Exception is actually being generated.

 

A couple tips.

You can toggle the breakpoint exception off and on using the checkbox next to it in the breakpoint window:

image

 

Remember how I said earlier that setting *Exception* as the breakpoint simply doesn’t work?  So, what do you do if you want to stop on all exceptions?  You set a breakpoint on Throwable and set “Subclasses of this Exception” to true, like so:

image

 

Warning though, Exceptions are commonly thrown, so expect hit a whole lot of breakpoints!

 

I know this information is probably common knowledge to people that live in Eclipse, but for those of us that come from other IDEs, its frustrating until figured out, and certainly not intuitive to figure out.  Thus this post, hope a few of you found it useful.

Programming


31. January 2014

 

When I started Flexamail ages ago, I created a Twitter account and did all the social media promotional stuff you were supposed to do.  Early on, we caught some pretty positive press ( LifeHacker, MakeUseOf ) and it lead to a huge amount of exposure.  Then the Twitter-verse started promoting it.  At one point, I had a Twitterimage user with over 4 million followers tweeted a link to Flexamail and it was retweeted an amazing 4,000 times!  I was expecting the traffic to come rolling in!

 

To put it mildly, I was disappointed with the results.  A totally of perhaps 45 million people received a tweet with a link to my site… how many link clicks?  About 3000.  Of those 3000, it resulted in about 200 account sign ups.  For some perspective the LifeHacker link resulted in tens of thousands of clicks and I would estimate 4 – 5K sign ups.  At this point in time I decided the Twitter was a bunch of people talking and very few people listening.

 

Therefore a couple years ago when I started GameFromScratch  I pretty much ignored Twitter completely until about a year ago and what an idiot I was.  It’s all a matter of targeting I suppose.  Now if someone posts a link to GameFromScratch on Twitter, from my very unscientific observation, I would say about 20% of a persons followers follow the link on average.  So for example, if someone with a thousand follower posts a link, it results in about 200 visits, which is pretty darned good.  A stranger phenomenon, the person with less followers tends to have a much higher click through.  So if someone has around 100 followers, you would often see almost half click a given link.

 

According to Google Analytics, a random sampling of social traffic breaks down like:

image

 

Obviously Reddit tops the list.  Reddit is a wonderful place to post for a content site like GameFromScratch, but I really don't recommend it for plugging a product, there is a sincere distaste towards those kinds of posts.  That is unless of course you share genuinely useful information, then you are loved.  Postmortems and sharing sales data are always welcome and could be a huge traffic boost.  Or of course you could consider a promoted reddit post, something I intend to explore at some point.

 

Next in traffic though is Twitter, followed by Facebook and the oh so random StumbleUpon ( about a year ago got 18,000 visits from SU in a single day! ).  So Twitter is certainly worth considering.

 

Which got me to wondering, when I looked over at the side of Twitter earlier day, there was a link for, well, basically paying for Twitter followers from Twitter ( not those shady buy-a-thousand-followers-for-5$ services ).  I got curious, could this be an effective way to promote a game ( or in my case, book )?  So I took a look.

 

The form itself is clever.  You say what regions and genders you want to target, what type of followers you would like to target ( pick someone famous, or use your own followers as the example ).  Then you can select a Tweet from your history that can be promoted.  You also decide whether you would like to pay per new follower, or pay per action ( retweet, favoriting, etc ).  It all sounded pretty good… great in fact.

 

Then it came down to pricing.  You can set a maximum budget and a daily budget.  I went with 20$ and 20$, so basically I was saying I am willing to pay a total of 20$.  The fact it let me go in with so low of an amount is certainly good for those of us on a smaller budget.  Next up came the bid… this is where you say how much you are willing to bid for your account to be promoted.  This works just like banner ads, basically you say “I am wiling to pay X amount to show my Twitter profile” when someone matching your target demographic views Twitter.  If you are the high bid, you are shown, if you aren’t, you aren’t ( and it costs you nothing ).  Then it all falls apart!

image

 

Suggested bid… $2.50 to $3.50!!!!  Three bucks a follower?  Seriously???  That would mean it would cost me $2,500 to get to where I am now!

 

Ouch.  Maybe for large companies with huge budgeting, this is worthwhile.  In fact, it is probably cheap compared to other forms of advertising.  For example, if Coke was running a Twitter campaign, 3$ a follower is probably dirt cheap compared to say… a SuperBowl spot.  But for a small developer hoping to promote a game, good god no!

 

I am mildly curious to see what happens if you do a 1 cent bid, Twitter’s suggestions be damned!  At 3 bucks a follower though, is it worthwhile?  No, not really.

Totally Off Topic


1. December 2013

 

I make no effort to disguise my dislike for Eclipse yet when working with LibGDX Eclipse is the path of least resistance. Fortunately there are other IDEs out there that can work with LibGDX, IntelliJ is my favorite of the options available. 

 

First off, you should be aware that there are currently some key limitations with the Gradle install.  Right now there is no support for GWT ( HTML5 ) or iOS projects.  So if those targets are important you should stick with Eclipse for now.

 

OK, let’s jump right in.  There are a couple things you need to have installed already.  First is a Java JDK, the second is the Android SDK ( not the ADT version! ).  I am not going into detail about how to install these, I simply assume you already have.  If you haven’t already, be sure to download and install IntelliJ IDEA, the free version has everything you need.

 

Installing the template

 

Now you need the LibGDX Gradle Template.  If you have git installed and configured ( you should! ) you can clone the template.  Open a command prompt or teminal, change to the directory you want your project to reside and run the command:

git clone https://github.com/libgdx/libgdx-gradle-template.git

It should run like so:

image

 

Alternately, you can download from github as a zip archive, download and then extract the contents to where you want the project to reside.

 

Now we will install gradle, this process is entirely automated.  In an elevated permission command prompt, change into the directory you just cloned/copied.  Now run the command:

gradlew clean

This will take a bit of time as it downloads and configured gradle and all the dependencies on your project.  Ideally you will see:

image

Now let’s make sure things worked right.  Run the command

gradlew desktop:run

 

Assuming everything went right, you should see:

image

 

Now generate a Intellij project.  Run the command

gradlew idea

This will create an IntelliJ project file with a .ipr extension.

image

 

Configuring IntelliJ IDEA

 

Load IntelliJ IDEA.

At the Quick Start Window, select Open Project

image

 

Navigate to the IPR file then select OK.

image

 

Configure the desktop project

 

Your Project should ( after you click the Project Tab ), look like this:

image

 

Let’s configure the desktop project first.  Select desktop in the project view and hit F4 or right click and select Open Module Settings:

image

 

Since you’ve never configured a JDK, you need to do that first.  In the future you shouldn’t have to do this step.  In the resulting dialog, select Project, then New… on the right side:

image

 

Select JDK in the drop down.  In the next dialog, navigate to and select the directory where you installed the Java JDK, then click OK.

image

 

Now that the Desktop project is configured, we need to create a Run or Debug configuration.  In the Run menu, select either Run… or Debug…

image

 

A menu will pop up, select Edit Configurations…

image

 

In the next dialog, click the + icon:

image

 

In the drop down, select Application:

image

 

Now we need to fill out the form.  You can optionally name your configuration, I went with Debug Desktop.  Next select “Use Classpath of module” and select Desktop.  In working directory, choose the assets folder in the Android project.  Click the … button to the right of Main Class and choose DesktopLauncher.  Finally click Apply then Debug.

image

 

If everything went right you should see:

image

 

Configure the Android Project

 

Now lets take a look at configuring the Android project, it’s a very similar process.

Right Click the Android project and select Open Module Settings.

Select Project, New->Android SDK

image

 

Browse to where you installed the Android SDK then click OK:

image

Pick whatever Java version and Android target you want.  Keep in mind, you need to install the SDKs as part of the Android SDK installation process:

image

 

Click OK, then Apply.

 

Now you can create a Debug or Run configuration for Android.  Select Run->Debug… or Run->Run…

Select Edit Configuration…

Click the + Icon, then select Android Application:

image

 

Now configure your run/debug configuration.  Name it, select Android from the Module pull down, pick what you want to target ( run the emulator vs run on a device ).  Finally click apply then Debug.

image

 

Once you’ve created a Run configuration, you can run your various different projects using this pull down:

image

 

 

Renaming your project

 

It is possible there is a much easier way to do this as part of the Gradle process ( I am certainly no Gradle expert! ) but once you have your project running, you probably want to rename it to something you want.  This means altering directories to match your new naming convention.  IntelliJ makes this fairly simple.

 

In the Project setting, select the Gear icon, then disable Compact Empty Middle Packages.

image

 

 

In this case, instead of com.badlogic.gradletest, I want it to be com.gamefromscratch.gradletest.

In the core project, select badlogic, right click and select Refactor->Rename…

image

 

Select Rename All

image

 

Select your new name, then click Refactor:

image

 

Now repeat the process in the Android folder, select and refactor badlogicgames.

image

 

This time select Rename Directory

image

Once again select the new value you want then click Refactor.

 

Finally locate AndroidManifest.xml and update the package name there as well

image

 

 

A world of note, refactoring wont update your project Run Configuration.  If you rename the project after creating a Run Configuration, you will see:

image

 

This is easily fixed, simply select Run->Edit Configurations:

image

 

Select your Desktop configuration and updated the Main Class to your newly renamed value:

image

 

… now you are up and running in IntelliJ.  It’s a bit more work, but certainly worth it in the end, especially if you dont need GWT or iOS support.  Hopefully those get added soon!

Programming


7. October 2013

 

On thing i’ve discovered working with GWT these past few weeks is, it’s slow… very very very slow.  I am developing on a newer laptop running a Haswell processor and SSD and my compilation times look like this:

image

 

254 seconds per compile is simply not tenable, especially during development.  You can avoid a compilation by working in DevMode, but this is exceedingly fragile at times.  As a result, I wanted to look into a way of speeding the process up.  Fortunately it’s a fairly simple process in the end.

 

The first culprit is the “Compiling permutation X” bit.  By default it is going to compile a version for every supported browser.  For release this is obviously advantageous, but during development it is bringing compile times to a crawl.  Fortunately, you only really need to develop for whatever browser you are testing in.  If you are working with a LibGDX project locate the file GwtDefinition.gwt.xml in the –html project.  There is one in the base project too, but that is not the file you are looking for.  It should look like this:

image

 

Edit that file to look like this:

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit trunk//EN" 
    "http://google-web-toolkit.googlecode.com/svn/trunk/distro-source/core/src/gwt-module.dtd">
<module>
    <inherits name='com.badlogic.gdx.backends.gdx_backends_gwt' />
    <inherits name='InputDemo' />
    <entry-point class='input.gamefromscratch.com.client.GwtLauncher' />
    <set-configuration-property name="gdx.assetpath" value="../input-android/assets" />
    <set-property name="user.agent" value="safari"/>
</module>

 

The line highlighted in yellow is the one you are interested in.  Basically you provide an entry for each browser you want GWT to compile for.  In my case I am working in Chrome which (oddly enough) doesn’t have it’s own user agent ( in the form value=”safari,ie9,other_values_here” ).  As Safari and Chrome have a common ancestor in Webkit, this user agent works.  You can also specify values for FireFox ( gecko ) and IE.  By building for just a single browser, we see a massive speedup.  In my after making the above change:

image

 

Down to 53 seconds… much better, but still far to long in my humble opinion.

 

Then one other idea struck me… I’m running a 32bit version of the JDK ( because so many tools still don’t play well with JDK7, FlashDevelop being the biggest ), so after a great deal of effort, I got and configured a 64 bit JDK and version of Eclipse.  Coincidentally, Eclipse really doesn’t seem to like sharing a workspace between 32 and 64bit installs!  Once I eventually got it working ( an hour and a half later… oh Eclipse, I so hate you ), I ran the GWT compiler again:

 

 image

 

31.5 seconds, almost a halving in development time.  So either Java 7, 64bit or possibly both resulted in a large decrease in compile time.

 

There is one final optimization I found, which is ironically to not optimize.  Just like with C++ compilers, you can create and optimized and unoptimized build.  By default GWT performs a great deal of optimization and during development, this is probably a waste.  Fortunately it can easily be disabled.  When you run a GWT compile, in the options window you can pass an additional parameter, –draftCompile.  It is available under the Advanced tab:

image

 

And the result:

image

17 seconds!  Much much much better!  Coincidentally, playing around with the memory amount available made little to no difference.  I actually experienced slightly slower compilation time when I increased it to 2G ( of 8 available on my machine ).  Obviously the less optimized version is going to run slower, but it shouldn’t be by a huge margin.

 

Remember though, when building for release, you want to re-enable all of these settings!  But for day to day development, 17 seconds is a heck of a lot better than 254s!

Programming


23. September 2013

 

I’ve recently been having a bit of a fight with Google development tools, GWT and the GWT plugin for Chrome on Windows 8 specifically.  Following the linked instructions I did manage to get the plugin installed, however today I started experiencing a new joy…  Every few minutes I would experience:

 

 

 

It would sometimes happen on load, other times when I tabbed back to Eclipse.  Apparently the GWT plugin is notoriously fragile.  Given the fact it doesn’t even run on Windows 8 without something of a song and dance, this isn’t really shocking.  I did however find a fix.  If you experience a GWT DMP Plugin crash in Chrome, check the following.

 

Go to chrome://extensions in Chrome.  Locate the plugin and click options:

image

 

In my case, there were no inclusions set for some reason.  Make sure localhost is added like so.  ( I did 127.0.0.1 too just in case… )

 

image

 

And, no more crashes!  That said, I’m still fed up with the entire process.  There is a project called Super Dev Mode that removes the plugin requirement completely, but there is an element of complexity involved. 

General


GFS On YouTube

See More Tutorials on DevGa.me!

Month List