Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (654)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [LibGDX]Making a game work for desktop AND android?  (Read 1910 times)
0 Members and 1 Guest are viewing this topic.
Offline P0jahn

Senior Devvie

Projects: 3

« Posted 2014-03-13 10:07:08 »

My game is using Slick2D and I am considering switching to LibGDX.

One thing that I dont get is how the hell is a game supposed to work for desktop AND android?

For example, when playing on desktop, I use my keyboard to move around. Thus, my game is listening for keystrokes.

When playing on android, I have to add buttons to the screen which we will use instead. This is a totally different behavior.
Offline Phibedy

Senior Devvie

Medals: 9

« Reply #1 - Posted 2014-03-13 10:35:24 »

You have to write the input for each plattform yourself,
but you should opimize the game for one plattform  Smiley
Offline Grunnt

JGO Kernel

Medals: 95
Projects: 8
Exp: 5 years

Complex != complicated

« Reply #2 - Posted 2014-03-13 10:36:49 »

Yeah that is an issue. You may want to make two seperate versions: one for Desktop, one for Android, that share a lot of the common code but differ in user interface code. In eXo I tried to get around this by designing the UI in such a way that its both useable on a touchscreen and on a PC (e.g. big buttons, only left mouse clicks). On the PC, in addition, I have added some keyboard shortcuts to make maximum use of the PC  user interface.

One other useful gadget to use for some games is an on-screen touchpad on Android, that works similar to keyboard input on PC:

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline JVallius
« Reply #3 - Posted 2014-03-13 11:08:37 »

One thing that I dont get is how the hell is a game supposed to work for desktop AND android?

I do not know. Depends on your game. Not every game is suitable for touch screen controls. And not every game is suitable for keyboard or mouse or gamepad.

Imho, the virtual on-screen pad is the worst controller ever created. Do not use it.

In code, using different controls in different platforms is very simple, you just compare which one you want to use, like:

if ( == ApplicationType.Android) {
} else if ( == ApplicationType.Desktop) {

Offline ImTroyMiller
« Reply #4 - Posted 2014-03-17 01:00:56 »

I made an onscreen keypad for my first game.

This is how you can read for screen touches in LibGDX...

         if (Gdx.input.justTouched()) {
            if (Gdx.input.getX() > 400 && Gdx.input.getX() < 500 && Gdx.input.getY() > 800 && Gdx.input.getY() < 900) {
               //Code for the above "touch-spot"
            if (Gdx.input.getX() > 600 && Gdx.input.getX() < 700 && Gdx.input.getY() > 800 && Gdx.input.getY() < 900) {
               //Code for the above "touch-spot"
            //Maybe some more "touch-spots"

I suggest adding another block of code when adding in input controls for your Android version, that way you can delete out the unnecessary code when your finished.
Offline pploco1996

Junior Devvie

Medals: 2
Exp: 1 year

« Reply #5 - Posted 2014-03-17 02:28:52 »

Start learning LibGDX for a couple of days and then you will realize that with a couple of "if" statements you can make the input work in any platform.
Offline Endos
« Reply #6 - Posted 2014-03-17 11:01:54 »

Do not use pooling for the input work, use the callbacks, this way you can avoid all the ifs to control the different platforms.

SUPERBLAM! - Super Mario type game for Android [iOS coming]
MINDTRIS - Most addictive puzzle ever for Android/iOS
Retroships - Space Shooter for Android
Offline tberthel
« Reply #7 - Posted 2014-03-17 11:10:14 »

I use the same input logic for all platforms. I just map the platform input into game input.  That way each new platform gets a mapping class based not just on platform but platform capabilities. Like Ouya has analog controls but not keyboard, mouse, orientation, or touch yet it is still Android.

Offline ImTroyMiller
« Reply #8 - Posted 2014-03-17 20:35:06 »

This is from a book...

switch ( { case Desktop:
// Code for Desktop application break;
case Android:
// Code for Android application break;
case WebGL:
// Code for WebGL application break; default: // Unhandled (new?) platform application break
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

bilznatch (24 views)
2015-08-04 11:03:17

SHC (39 views)
2015-08-01 03:58:20

Jesse (24 views)
2015-07-29 04:35:27

Riven (45 views)
2015-07-27 16:38:00

Riven (25 views)
2015-07-27 15:35:20

Riven (27 views)
2015-07-27 12:26:13

Riven (18 views)
2015-07-27 12:23:39

BurntPizza (41 views)
2015-07-25 00:14:37

BurntPizza (53 views)
2015-07-24 22:06:39

BurntPizza (33 views)
2015-07-24 06:06:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!