Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (515)
Games in Android Showcase (122)
games submitted by our members
Games in WIP (577)
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 1063 times)
0 Members and 1 Guest are viewing this topic.
Offline P0jahn

Senior Duke


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 Duke


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: 92
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:
http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/Touchpad.html

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:

1  
2  
3  
4  
5  
if (Gdx.app.getType() == ApplicationType.Android) {
   handleAndroidControls();
} else if (Gdx.app.getType() == ApplicationType.Desktop) {
   handleDesktopControls();
}

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...

1  
2  
3  
4  
5  
6  
7  
8  
9  
         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
« 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.

Bored Birds - End with your boredom for Android
Retroships - Space Shooter for Android
Ultimate - 2D Side-Scrolling Platformer project
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...

1  
2  
3  
4  
5  
6  
7  
8  
 
switch (Gdx.app.getType()) { 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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (31 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (40 views)
2014-10-26 19:37:11

Luminem (21 views)
2014-10-26 10:17:50

Luminem (25 views)
2014-10-26 10:14:04

theagentd (31 views)
2014-10-25 15:46:29

Longarmx (61 views)
2014-10-17 03:59:02

Norakomi (57 views)
2014-10-16 15:22:06

Norakomi (46 views)
2014-10-16 15:20:20

lcass (43 views)
2014-10-15 16:18:58
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!