Project setup, running and debugging

View: 1224    Dowload: 0   Comment: 0   Post by: daii   Category: Mobile applications   Fields: Game - Entertainment

File has been tested

Attention: this is extremely outdated and NOT supported anymore! Please use the Gradle-based setup instead

Libgdx is very Eclipse centric due to its Android and HTML5/GWT back-ends. This article discusses how to setup libgdx projects for Eclipse. Check out this Using libgdx with IntelliJ IDEA if you use IntelliJ. If you prefer to use a different IDE, please refer to the bottom of this page which outlines the dependencies in detail.

Prerequisites

To target Windows, Linux, Mac OS X, Android and HTML5 you will need:

To additionally target iOS you will also need:

  • A Mac, iOS Development does not work on Windows/Linux thanks to Apple.
  • The latest XCode, which you can get from the Mac OS X App Store for free
  • RoboVM, simply install the Eclipse plugin, or use the command line version.

Tutorial Video

Follow this if you don't want to read a lot of text. Otherwise continue below.

Libgdx setup video

Using "Libgdx Setup"

As of version 0.9.3, libgdx comes with an easy to use application called "Libgdx Setup" by Aurelien Ribon. The following steps will create everything needed to develop for the desktop, android, ios and html5.

  • Download the gdx-setup.jar from http://libgdx.badlogicgames.com/nightlies/dist/gdx-setup.jar. The jar is also contained in all stable and nightly releases.
  • Execute the jar by double clicking it or from the command line via java -jar gdx-setup.jar
    • Specify your project's configuration (Configuration Panel)
    • Specify the libgdx stable/nightly release zip file or press one of the buttons to download the latest stable/nightly release (Library Selection Panel).
    • Hit the "Generate projects" button (Generation Panel)
  • Open Eclipse and import the generated projects into your workspace
    • File -> Import -> Existing Projects into Workspace
    • Click "Browse", select the folder containing the generated projects.
    • Make sure all the projects are checked, then click "Finish"
    • To fix the error of the HTML5/GWT project, go to the "Problems" view, right click the error message "The GWT SDK JAR gwt-servlet.jar is missing in the WEB-INF/lib directory" and select "Quick Fix". Click "Finish".

Project Layout

Assuming you named your project "my-gdx-game" in the Setup UI, you will end up with 4 projects:

  • Core project ("my-gdx-game"): contains all the code of your application, minus the so called starter classes. All other projects link to this project. This project is usually referred to as the "core project".
  • Android project ("my-gdx-game-android"): contains the starter class and other necessary files to run your application on Android. The assets/ folder stores the assets of your application for all platforms.
  • Desktop project ("my-gdx-game-desktop"): contains the starter class to run your application on the desktop. Links to the Android project's assets/ folder as well as the core project.
  • HTML5 project ("my-gdx-game-html"): contains the starter class and other necessary files to run your application as a native HTML5 application. Links to the Android project's assets/ folder (see gwt.xml file) as well as to the core project.
  • iOS RoboVM project ("my-gdx-game-robovm"): contains the starter classes and other necessary files to run your application on iOS through RoboVM. Links to the Android project's assets/ folder (see robovm.xml) as well as the core project.

All your application's assets should be stored in the Android project's assets folder. The desktop, iOS and HTML5 projects link to this folder, so there is no need to store duplicates of these assets.

Running Your Application

  • Desktop: Right click the desktop project, Run As -> Java Application. Select the desktop starter class (e.g. Main.java).
  • Android: make sure you have a device connected and that it shows up in DDMS. If you do not know what this means, please refer to the Android Developer Guide. Right click your Android project, Run As -> Android Application.
  • iOS RoboVM: Right click the robovm project, Run As -> iOS Device App to run on a connected device, or Run As -> iOS Simulator App to run on the iOS simulator. If you run on a device, you need to provision it to be able to deploy to it!
  • HTML5: there are two modes in which you can run your application.
    • development/hosted mode: runs the actual Java code via GWT plugin magic and allows debugging and hot swapping code (kind of).
      • Right click the HTML5 project, Run As -> Web Application.
      • In the "Web Development" view, click the URL. Your standard browser will open up. If you have not installed the GWT plugin yet, you will be prompted to do so. After installation of the plugin, simply refresh the site in the browser.
    • production/web mode: you will need a web server that serves the compiled files (e.g.Nginx or a browser that allows to execute JavaScript from local files.
      • Right click the HTML5 project, Google -> GWT Compile
      • Once compiled, place the contents of the war/ directory into a directory your web server can serve. Omit the WEB-INF folder.
      • Point your browser at an URL which will display the .html file.

Debugging Your Application

  • Desktop: Right click the desktop project, Debug As -> Java Application. Select the desktop starter class (e.g. Main.java). Set breakpoints where you need them, hot swap code (edit & save while debugging) to quickly test changes without restarting the app.
  • Android: assuming you have a device connected, Debug As -> Android Application. Hot swapping is not supported, but you can use the DDMS perspective to check your memory usage, profile your application and so on. Refer to the Android Development Guide for more information.
  • iOS RoboVM: debugging is currently not supported by RoboVM
  • HTML5:
    • development/hosted mode: runs the actual Java code via GWT plugin magic and allows debugging and hot swapping code (kind of).
      • Right click the HTML5 project, Debug As -> Web Application.
      • In the "Web Development" view, click the URL. Your standard browser will open up.
      • Set breakpoints in your Java code. If you edit & save code, you'll have to refresh your browser for the changes to take effect. This will essentially restart your application. It's faster than recompiling though.
    • production/web mode:
      • Right click the HTML5 project, Google -> GWT Compile
      • Change the flags in "Advanced" to -strict -draftCompile and the "Output Style" to "detailed". This will produce very readable Javascript that you can map almost 1:1 to your Java code.
      • Once compiled, place the contents of the war/ directory into a directory your web server can serve. Omit the WEB-INF folder. # Point your browser at an URL which will display the .html file. # Open up Firebug or similar tools, go to the JavaScript and set breakpoints, watch the callstack and so on. To find a Java Class method, simply search for the package/class/method name.
    • super dev mode: through the power of source maps, you can also debug compiled JS as if it where Java, directly in your browser. See this blog post on libgdx and super dev mode

Manual Project Setup

Please refer to Manual Project Setup

Project setup, running and debugging

Attention: this is extremely outdated and NOT supported anymore! Please use the Gradle-based setup instead Libgdx is very Eclipse centric due to its Android and HTML5/GWT back-ends. This article discusses how to setup libgdx projects for Eclipse. Check out this Using libgdx with IntelliJ IDEA if you use IntelliJ. If you prefer to use a different IDE, please refer to the bottom of this page which outlines the dependencies in detail.

Posted on 12-11-2016 

Comment:

To comment you must be logged in members.

Files with category

  • Terror Smash Game (Android)

    Terror Smash Game (Android)

    View: 0    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    Terror Smash is a simple game in which the player attacks the terrorists through tapping the screen. Meanwhile, if you tap the civilians, a life will be deducted.

  • Can K.O. Demo

    Can K.O. Demo

    View: 0    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    This game is created in Unity Game Engine. Can K.O. is a simple game all you need to do is to hit all the cans on the shelf by swiping the ball. The goal of this game is to knock as many cans as you can using only few balls.

  • Slot Machine Game Application in Android

    Slot Machine Game Application in Android

    View: 9    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    This is a Slot Machine Game Application in Android created using Basic4Android. This app features to roll images randomly, has coin slot, points earned, paid status, reset button, and has a a 50 coin default credit on the first play. Download the...

  • Flashlight Application in Android

    Flashlight Application in Android

    View: 6    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    Hi there! I have created an app again named Flashlight Application. This application is programmed in Basic4Android that has the capabilities to trigger to on your flashlight in your phone. This is compatible with Android 2.2 version and above....

  • Mobile Computer Dictionary Application in Android

    Mobile Computer Dictionary Application in Android

    View: 12    Download: 1   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    Hi. This is an application that i have created in Basic4Andriod and SQLite Manager entitled Mobile Computer Dictionary . This application features to search and display the related computer definitions. I have just upload and completed it up to...

  • Android FRONT CAMERA App v1.2

    Android FRONT CAMERA App v1.2

    View: 8    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    Hi guys! This is my another creation in Android that i have created my own version of accessing Front Camera. This app features to capture photos using the front camera of your Android phone. When clicking the capture button, it will automatically...

  • Voice Recorder Application in Android

    Voice Recorder Application in Android

    View: 10    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    I've been into many experiments in Android until I came up making this app called Voice Recorder Application . This app features to record any audio or voice and will save at your default directory in Android phone as " VoiceRecord.wav ". First,...

  • Intent Example using Eclipse

    Intent Example using Eclipse

    View: 34    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    Android intent using eclipse. This sample app can invoke facebook.com, dial nos. and can display contacts. Instructions: 1. Extract the zip file. 2. Open the Project using Eclipse Indigo or Juno Eraser Software Solution Joemel E. Resare, MIT...

 
File suggestion for you
File top downloads
Codetitle.net - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.net Develope by Vinagon .Ltd