Tuesday, 16 September 2014

Introduction to Libgdx and Project Setup



FOR Video tutorial of libgdx AND BOX2D


This blog will take you on an exciting tour to show and teach you about game
development using the open source Libgdx framework. Actually, you have chosen
just the right time to read about game development as the game industry is in a
remarkable state of change.



Creating a libgdx project

Libgdx comes with a file called gdx-setup.jar which is an executable UI and command line tool. You can simply execute the JAR file which will open the setup UI.
To execute the JAR file at the command line:
java -jar gdx-setup.jar

Download gdx-setup.jar

Specify your application name, your Java package name, the name of your main class, the output directory, and the path to your android sdk. Next, you can select what platforms you want to support. Note: once chosen, you'll have to add new platforms manually!. Finally, you can select extensions to be included in your app. Some may not work on all platforms, for which you'll get a warning. When you've set everything, click "Generate". Now you are ready to import the project into your IDE, run, debug and package it!
  • Eclipse





























Importing Your Project

Go to File -> Import -> Gradle -> Gradle Project, click Browse and navigate to the root folder of your project, then click Build Model. After a while, you'll see a root project and subprojects (android, core, desktop, html, ios). Select all the projects and click Finish. Note that this process can take a minute or two the first time you do it, as Gradle and some dependencies will be downloaded in the background.

Running Your Project

  • Desktop: Right click the desktop project, Run As -> Java Application. Select the desktop starter class (e.g. DesktopLauncher.java).
  • Android: make sure you have a device connected and that it shows up in DDMS (see 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: Right click the html project, Run As -> External Tools Configuration. Create a new configuration by double clicking the Programentry in the left sidebar. Give the configuration a name, e.g. GWT SuperDev. Set the location field to the gradlew.bat (Windows) or gradlew (Linux, Mac) file. Set the working directory to the root folder of your project. Specifyhtml:superDev as the Argument. Press 'Apply', then 'Run'. Wait until you see the message The code server is ready. in the console view, then open the URL http://localhost:8080/html. You can leave the server running. If you change code or assets, simply click the SuperDev Refresh button in the browser. This will recompile your app and reload the site.
Once this bug in the Gradle tooling API is fixed, we can simplify running the HTML5 by using the Gradle integration. At the moment, the Gradle process will run forever even if canceled.

Introduction to Libgdx
Libgdx is an open source, cross-platform development framework, which is designed mainly, but not exclusively, to create games using the Java programming language. Besides Java, Libgdx also makes heavy use of the C programming language for  performance-critical tasks, to incorporate other C-based libraries and to enable  cross-platform capabilities. Moreover, the framework abstracts the complex  nature of all its supported target platforms by combining them into one common Application Programming Interface (API). One of the highlights of Libgdx is the ability to run and debug your code on the desktop as a native application. This enables you to use very comfortable functions of the Java Virtual Machine (JVM)such as Code Hot Swapping, which in turn lets you immediately see the effect of your changed code at runtime. Therefore, it will significantly reduce your time to iterate through different ideas or even to find and fix nasty bugs more quickly.
Another critical point is to understand that Libgdx is a framework and not a game engine that usually comes with lots of tools, such as a full-blown level editor and a completely predefined workflow. This might sound like a disadvantage at first but actually it turns out to be an advantage that enables you to freely define your own workflow for each project. For example, Libgdx allows you to go low-level so you could add your own OpenGL calls if that really became necessary at some point. However, most of the time it should be sufficient enough to stay high-level and  use the already built-in functionalities of Libgdx to realize your ideas.

Goals and Features

Libgdx is a Java game development framework that provides a unified API that works across all supported platforms.
The framework provides an environment for rapid prototyping and fast iterations. Instead of deploying to Android/iOS/Javascript after each code change, you can run and debug your game on the desktop, natively. Desktop JVM features like code hotswapping reduce your iteration times considerably.
Libgdx tries not be the "end all, be all" solution. It does not force a specific design on you. Pick and choose from the features below.

Cross-Platform

A single API to target:
  • Windows
  • Linux
  • Mac OS X
  • Android (2.2+)
  • BlackBerry
  • iOS
  • Java Applet (requires JVM to be installed)
  • Javascript/WebGL (Chrome, Safari, Opera, Firefox, IE via Google Chrome Frame)

Graphics

Utilities

Tools

3rd Party Support

Libgdx can be integrated with many 3rd party tools. We love:
  • Spine - 2D Skeletal Animation
  • Nextpeer - Mobile multiplayer made easy
  • Saikoa - makers of ProGuard and DexGuard

Audio

Input Handling

Math & Physics

File I/O & Storage

No comments:

Post a Comment