I,
Libgdx is a cross-platform 2D/3D Game Development Framework written in Java/C ++. Ibgdx is compatible with most microcomputer platforms (Standard javase implementation, running on Mac, Linux, windows, and other systems, and recently added HTML5 support) and Android platforms (android1.5 and above, android2.1 and above can be used up to full power ). Libgdx comes with an image decoder in native mode. The pixmap provided by libgdx can perform pixel-level rendering on the specified image, so that it does not depend on the android bitmap to load and process the image. It can support PNG, JPG, and BMP, the support for GIF images has been added to the last two versions (if you want to make a large number of animations, GIF images can be scaled twice when the image quality cannot be reduced too much, you can understand this ).
For libgdx platform construction is not much repeat, you can see another post in the android bus http://www.apkbus.com/android-19745-1-1.html
Some of the content is very detailed and can help you get started quickly. The tutorials in this series are intended to help you further perform operations on the basis of getting started and share some of the problems I have encountered, this prevents you from wasting valuable time on these issues. You can download the latest libgdxat http://code.google.com/p/libgdx. Here, we also want to remind you that libgdx is divided into latest releases and nightlies. The former is a officially released version, and the latter is a version that is updated at any time. We recommend that you do not have any special requirements, it is best to use lastest release to avoid some strange problems. I am using the latest version 0.9.4, which includes a lot of new content (including 3D ), the efficiency is also significantly improved compared with the old version. It is best not to use version 0.9.2, because version 0.9.4 modifies some interfaces, I used to spend some time modifying the code when I updated the libgdx version of my game from 0.9.2 to 0.9.4, because the original interfaces and functions have been deprecated... The first article focuses on the introductory content, here we will first post a simple demo for you to learn (provided that you have set up the libgdx environment ). By the way, you only need:
- Armeabi/
- Armeabi-v7a/
- Gdx-backend-android.jar
- GDX. Jar
These four files can be, the specific use of the method can be http://www.apkbus.com/android-19745-1-1.htm
Libgdx is a game library that supports 2D and 3D Game Development. It is compatible with most microcomputer platforms (Standard javase implementation and can run on Mac, Linux, windows, and other systems) it can be used with the Android platform (android1.5 or above, and android2.1 or above can be used at full power ).
Logo:
Upload at a.m. on February 16
Download Attachment(5.65 KB)
Address: http://code.google.com/p/libgdx/
First download the latest jar, I downloaded the libgdx-0.9.2.
Upload at a.m. on February 16
Download Attachment(49.84 KB)
Create an android project, File> New> Project> Android project. The sdk I selected is 1.6, and the minimum option is 1.5.
Create a new folder libs (the name is fixed and cannot be changed at will), copy the downloaded jar into, Android platform only need to copy GDX. jar and gdx-backend-android.jar.
Add references, and then copy the armeabi and armeabi-v7a folders to the libs folder.
Strictly follow the steps !!!!!!!!!!!!!!!!!!!!!!
Upload at a.m. on February 16
Download Attachment(46.63 KB)
Then write a small item to test whether the environment is correct.
The new class hellogameactivity inherits the androidapplication class.
- Package com. cnblogs. htynkn;
- Import com. badlogic. GDX. backends. Android. androidapplication;
- Import Android. OS. Bundle;
- Public class hellogameactivity extends androidapplication {
- @ Override
- Public void oncreate (bundle savedinstancestate ){
- Super. oncreate (savedinstancestate );
- Initialize (New firstgame (), false );
- }
- }
Copy code
- Initialize (New firstgame (), false );
Copy codeIt is the key to starting the game. firstgame is a class that implements applicationlistener. The Code is as follows:
- Package com. cnblogs. htynkn;
- 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 the 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
- }
- }
Copy codeBecause no actual content is written, the effect is a black box.
Upload at a.m. on February 16
Download Attachment(14.37 KB)
The next article is about image rendering. Note: If you carefully observe logcat, you will find an error: E/libegl (382): couldn 'tload <libhgl. so> Library (cannot load Library: load_library [984]: Library 'libgl. so 'not found) It doesn't matter. This is because the system fails to load the hardware OpenGL driver and returns to the software processing method, not a defect or error. Let's first write a class
- Public class mygame implements applicationlistener {
- Public void create (){
- // Stub
- }
- Public void render (){
- // Stub
- }
- Public void resize (INT width, int height ){
- // Stub
- }
- Public void pause (){
- // Stub
- }
- Public void resume (){
- // Stub
- }
- Public void dispose (){
- // Stub
- }
- }
Copy code
Applicationlistener is an interface. We can easily see that all classes that implement this interface have a common feature. They all go through a creation, rendering (render), pause, and continue, destruction and other processes, when the corresponding time occurs, the corresponding function will be called for your own use. In particular, the render () function is a function that is constantly called by the system (of course, this instance meets the running conditions). Therefore, we can implement many operations in the render () function, do not perform time-consuming operations to avoid blocking the UI thread. Next we will start a libgdx game! Write another class
- Public class libgdxactivity extends androidapplication {
- @ Override
- Public void oncreate (bundle savedinstancestate ){
- Super. oncreate (savedinstancestate );
- Initialize (New mygame (), false );
- }
- }
Copy codeThis completes the compilation of the first libgdx program! Of course, a variety of import XXXX needs to be added to the source code. We will not add it here. In addition, we will attach the source code for you to download.
Query the official documentation and you can see
Java. Lang. Object
| Activity
|Com. badlogic. GDX. backends. Android. androidapplication
What does this mean ?? That is to say, androidapplication inherits from the activity in the API, so we also need to register it in manifest. Here we will not specifically describe how to register it. Everyone should know it! In addition, this provides a better question for everyone to think about. Since androidapplication inherits from activity, can we use intent to redirect like other activities? The answer is yes, but it is not that simple. I will focus on this issue in the subsequent articles.
AsInitialize (New mygame (), false); this statement is an essential condition for starting libgdx. It cannot be started without executing libgdx, the first parameter is an instance of the class that implements the applicationapplication interface. If the second parameter is set to true, OpenGL 2.0 is used when OpenGL 2.0 is available.