I want to include libGDX in an article abt mobile frameworks

Anything libgdx related goes here!

I want to include libGDX in an article abt mobile frameworks

Postby shoe » Fri Mar 16, 2018 10:15 am

Hi,

I am about to write an article about mobile frameworks for a well known programming magazine (probably could disclose this but I didn't really read the legalese so...). Basically it is a short introduction of the various frameworks and the description of the steps to build a minimal app that (in the optimal case) runs on Android and iOS.

The minimal app has a button and a text area. Pressing the button is supposed to fetch the contents of the "clipboard" (text somebody previously copied in another app) an then display the fetched contents in the text area.

I am not really familiar with libGDX so far so I wondered if an expert could take the few minutes to tell me the absolute "shortest" way to get to this app. Source code, Gradle build, etc. to build and run it on Android and iOS.

Thanks,
shoe
shoe
 
Posts: 12
Joined: Fri Feb 23, 2018 11:20 am

Re: I want to include libGDX in an article abt mobile framew

Postby evilentity » Fri Mar 16, 2018 3:46 pm

Hi!

The app itself is the easy part, the initial setup might be problematic.

If you have android dev environment set up, it should be relatively painless. If not, try following this guide https://github.com/libgdx/libgdx/wiki/S ... ,-NetBeans) I suggest using Intellij IDEA as your ide.

Once you all required stuff, download the setup app http://libgdx.badlogicgames.com/download.html
Run it and setup your project, fill in the required stuff, probably uncheck html in sub projects and box2d in extensions. You want need that for this project.
I also strongly suggest checking 'VisUI' in the third party extensions, it makes setting up gui a lot easier.
You can also check IDEA project files in Advanced dialog.

Then you can generate the project.
You can use old tools when asked.
Sometimes some error pop up, but you dont need to worry about them if the files exist in proper place.


Open the root project with ide. In Idea, click import gradle project in a popup. Uncheck separate source sets.

If you dont have specified android build tools you can either change them in android/build.gradle or download them.

If there are no errors at this point, you should be able to run the project with gradle. I suggest running on actual devices, but emulators should work as well.

On the right theres a gradle tab.
To run on desktop start task :desktop:run in :desktop/tasks/other
To run on android start task :android:installDebug in :android/tasks/install
To run on android start task :ios:launchiOSDevice in :ios/tasks/other, this will take a while on first run. If you test on a device, you will need to add -Probovm.arch=arm64 to the arguments, at the top near the green arrow, edit configurations. Add it to that task.

As far as code goes, replace the main class in core/src/... with this:
Code: Select all
package com.mygdx.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.kotcrab.vis.ui.widget.VisTextArea;
import com.kotcrab.vis.ui.widget.VisTextButton;

public class MyGdxGame extends ApplicationAdapter {
   SpriteBatch batch;
   Stage stage;
   Table root;

   @Override
   public void create () {
      VisUI.load(VisUI.SkinScale.X2);
      batch = new SpriteBatch();
      stage = new Stage(new ScreenViewport(), batch);

      root = new Table();
      root.setFillParent(true);
      stage.addActor(root);

      final VisTextArea area = new VisTextArea();
      root.add(area).expand().fill().pad(8).row();
      VisTextButton paste = new VisTextButton("Paste");
      root.add(paste).pad(8);
      paste.addListener(new ClickListener(){
         @Override public void clicked (InputEvent event, float x, float y) {
            area.setText(Gdx.app.getClipboard().getContents());
         }
      });
      Gdx.input.setInputProcessor(stage);
   }

   @Override
   public void render () {
      Gdx.gl.glClearColor(0.5f, 0.5f, 0.5f, 1);
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

      stage.act();
      stage.draw();
   }

   @Override public void resize (int width, int height) {
      stage.getViewport().update(width, height);
   }

   @Override
   public void dispose () {
      batch.dispose();
      VisUI.dispose();
   }
}


If you have any problems, ask here

Good luck!
Looking for a freelancer? PM me!
evilentity
 
Posts: 4351
Joined: Wed Aug 24, 2011 11:37 am

Re: I want to include libGDX in an article abt mobile framew

Postby shoe » Fri Mar 16, 2018 6:29 pm

Thank you very much!

Will this build for iOS, run in the simulator?

The build script also will deploy to Google's Play Store and the Apple Store?
shoe
 
Posts: 12
Joined: Fri Feb 23, 2018 11:20 am

Re: I want to include libGDX in an article abt mobile framew

Postby evilentity » Fri Mar 16, 2018 6:52 pm

For simulator you can run task Ios:launchIPhoneSimulator optionally with -Probovm.device.name="iPhone 6" argument for specific sim.
Store deployment is manual. For android you create signed apk and upload it, for ios you create ipa and upload it via application loader from xcode. There are tasks for both of those.
Looking for a freelancer? PM me!
evilentity
 
Posts: 4351
Joined: Wed Aug 24, 2011 11:37 am

Re: I want to include libGDX in an article abt mobile framew

Postby shoe » Fri Mar 16, 2018 7:01 pm

Thanks! I will definitely try it tomorrow!

I assume you obviously cannot build the ipa without OSX and XCode?
shoe
 
Posts: 12
Joined: Fri Feb 23, 2018 11:20 am


Return to Libgdx

Who is online

Users browsing this forum: Google [Bot] and 1 guest