4.3 libgdx startup class and Configuration

Source: Internet
Author: User
Tags libgdx

(Original: http://www.libgdx.cn/topic/45/4-3-libgdx%E5%90%AF%E5%8A%A8%E7%B1%BB%E4%B8%8E%E9%85%8D%E7%BD% AE)

Each platform must have a startup class. This category is independent for each platform. Here we will only introduce android.

 

** Android **

The main () method is not applicable to Android applications, but an activity is required. Open the android project and find the following code:

Package CN. libgdx. game;

 

Import Android. OS. Bundle;

 

Import com. badlogic. GDX. backends. Android. androidapplication;

Import com. badlogic. GDX. backends. Android. androidapplicationconfiguration;

 

Public class mainactivity extends androidapplication {

@ Override

Public void oncreate (bundle savedinstancestate ){

Super. oncreate (savedinstancestate );

 

Androidapplicationconfiguration CFG = new androidapplicationconfiguration ();

Cfg. usegl20 = false;

 

Initialize (New mygdxgame (), CFG );

}

}

 

Here, the main portal method is the oncreate () method of activity. In an android application, an android application can have multiple activities. However, only one activity can be found in libgdx games. Different Game interfaces are completed in libgdx instead of multiple interfaces. The reason for this is that you also need to create a new OpenGL context to create an activity, which means all resources need to be reloaded.

 

** Androidmanifest. xml file **

<? XML version = "1.0" encoding = "UTF-8"?>

<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"

Package = "cn. libgdx. Game"

Android: versioncode = "1"

Android: versionname = "1.0" type = "codeph" text = "/codeph">

 

<Uses-SDK Android: minsdkversion = "5" Android: targetsdkversion = "15"/>

 

<Application

Android: icon = "@ drawable/ic_launcher"

Android: Label = "@ string/app_name">

<Activity

Android: Name = ". mainactivity"

Android: Label = "@ string/app_name"

Android: screenorientation = "Landscape"

Android: configchanges = "keyboard | keyboardhidden | orientation">

<Intent-filter>

<Action Android: Name = "android. Intent. Action. Main"/>

<Category Android: Name = "android. Intent. Category. launcher"/>

</Intent-filter>

</Activity>

</Application>

 

</Manifest>

 

Add permission:

<Uses-Permission Android: Name = "android. Permission. record_audio"/>

<Uses-Permission Android: Name = "android. Permission. write_external_storage"/>

<Uses-Permission Android: Name = "android. Permission. Vibrate"/>

 

(Www.libgdx.cn is copyrighted. If you need to reprint it, indicate the source)

4.3 libgdx startup class and Configuration

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.