Use libgdx on Android

Source: Internet
Author: User
Tags libgdx

Use libgdx on Android


Libgdx is an excellent 2D/3D cross-platform physical engine. Today we will introduce how to use it on Android:



1.

In



2.

Decompress gdx-helloworld-0.9.2.zip, and thenImport GDX-helloworld directly in eclipse,Run as Java application directly, A dialog box is displayed,We can select helloworlddesktop., As follows:




Program:






Next we will introduce how to port to Android:

1.

Create an android project for libgdx as follows:






2.

Create a new libs folder under the root directory of the project, copy the armeabi and armeabi-v7a folders under libgdx to libs, and copy GDX. jar and gdx-backend-android.jar to libsThe result is as follows:




3.

Right-click the libgdx project, select properties, and click "add jars" in libraries of Java build path to addGDX. jar and gdx-backend-android.jar, As follows:





4.

Modify the libgdxactivity. Java file as follows:

package com.test.libgdx;import android.app.Activity;import android.os.Bundle;import com.badlogic.gdx.backends.android.AndroidApplication;public class LibgdxActivity extends AndroidApplication {    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);                initialize(new FirstGame(), false);    }}




5.

Create a firstgame class, As follows:

Package COM. test. libgdx; import COM. badlogic. GDX. applicationlistener; import COM. badlogic. GDX. GDX; import COM. badlogic. GDX. graphics. gl10; import COM. badlogic. GDX. graphics. g2d. spritebatch; public class firstgame implements applicationlistener {/* spritebatch for plotting */private spritebatch batch; @ override public void create () {batch = new spritebatch (); // instantiate} @ override public void dispose () {// todo auto-generated method stub} @ override public void pause () {// todo auto-generated method stub} @ override public void render () {GDX. GL. glclear (gl10.gl _ color_buffer_bit); // clear screen batch. begin (); batch. end () ;}@ override public void resize (INT width, int height) {// todo auto-generated method stub} @ override public void resume () {// todo auto-generated method stub }}


6.

Run as Android Application in eclipse, as shown below:




Since we have not drawn any image, the result is a black screen, but at least the libgdx configuration is correct.





Done!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.