Friday, 19 September 2014

Kicking your game to life

Let us take a moment to discuss what a game basically consists of. From a very
high level point of view, a game can be split up into two parts: game assets and
game logic.

Game assets include everything that is going to be used as a kind of working
material in your game, such as images, sound effects, background music,
and level data.

Game logic is responsible for keeping track of the current game state and to only
allow a defined set of state transitions. These states will change a lot over time due
to the events triggered either by the player or by the game logic itself. For example,
when a player presses a button, picks up an item, or an enemy hits the player, the
game logic will decide for the appropriate action to be taken. All this is better known
as game play. It constrains the ways of action in which a player can interact with the
game world, and also how the game world would react to the player's actions.







The very first step is to initialize the game, that is, loading assets into memory,
creating the initial state of the game world, and registering with a couple of
subsystems such as input handlers for keyboard, mouse and touch input,
audio for playback and recording, sensors, and network communication.
When everything is up and running, the game logic is ready to take over and will
loop for the rest of the time until the game ends and will then be terminated. This
kind of looping is also referred to as the game loop. Inside the game loop, the game
logic accumulates all (new) data it is interested in and updates the game world
model accordingly.

It is very important to consider the speed at which updates will occur in the game
world. Currently, the game would just run at the maximum speed of the available
hardware. In most cases this is not a desirable effect because it makes your game
dependent on the processing power and the complexity of the scene to be rendered,
which will vary from computer to computer. This implies that your game world
will also progress at different speeds on different computers with an almost always
negative impact on the game play.

The key to tackle this issue is to use delta times to calculate the fractional progress
of the game world. Now every update to the game world will occur in relation to
real time that has passed since the last frame was rendered. You will see how this
actually works with Libgdx in later examples.

What you have just read was an overview of the basic concept for creating games.
Yes, it is that simple! Frankly speaking, there is a lot more to learn before your
application becomes a real game. There are lots of topics and concepts waiting to
be discovered in this book. For instance, you will need to understand how to use
and manage different images in an efficient manner. Efficiency becomes even more
important if you plan to target mobile devices such as Android smartphones, where
available resources are constantly scarce.



Key to success lies in planning
Great! Now you have a basic understanding of what a game is and may need. It
appears to be a good idea to dedicate some additional time to think about your
first game project and create a plan for it. In general, planning your game projects
is what you should always do in the first place before any actual work is done. For
novice game developers it might be very tempting to skip this planning phase,
which admittedly is a lot more fun in the beginning, but this approach is very likely
to fall short in the long run. You will need some sort of outline of what you want to
achieve. It does not have to be a very long and detailed description.


A simple and brief feature list of your design goals will do just fine for this purpose.
The reason behind this is that you will make yourself aware of each single feature
that is part of your game. In addition, this list will also serve you as a great tool to
measure and compare your progress in the game during the development phase.
Please bear in mind that game development is a very dynamic and iterative process.
Although you should try to adhere to your list of design goals for most of the time,
there should always be room to adapt to shifting requirements. Just keep in mind
that adhering to the list will make sure that you are going to push development in
the right direction. Conversely, it will let you focus on the important parts first,
while also protecting you from running out of time and taking too many detours
that prevent you from reaching the finish line due to unclear goals.

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