Getting started with the game frame LIBGDX

Source: Internet
Author: User
Tags clear screen prepare libgdx
transferred from: http://blog.csdn.net/cping1982/article/details/6176191#
Libgdx is a game library that supports 2D and 3D games and is compatible with most PC platforms (standard Javase implementations that can run on Mac, Linux, Windows and other systems) and Android platform (Android1.5 above can be used, Android2.1 above the full power play),

The LIBGDX consists of audio, files, graphics, math, physics, scenes, and utils, which correspond to the operation of the sound in the LIBGDX, the file reading, the 2d/3d rendering, the LIBGDX drawing-related operations, box2d Package, 2d/3d game components (3D parts currently no components), and LIBGDX built-in tool classes.

About the GDx class in LIBGDX:

On the surface, the GDx class occupies less than 2KB, and does not even have a single line of functions that can be executed directly, and nothing important to say.

However, the real gdx is the core of the Libgdx class library, without which you will be unable to move, not only running graphics, Input, Files, Audio, The necessary instances of LIBGDX key parts, such as androidapplication, are injected into the static variables of the corresponding graphics, input, files, audio, and apps in GDX during LIBGDX initialization. Even LIBGDX to the OpenGL interface (or Opengles, depending on the LIBGDX operating platform, the following collectively known as OpenGL) GL10, GL11, GL20, Glcommon and other packaging classes will be injected into the graphics instantiation of Gl10, GL11 , GL20, and GL are among the four static variables that are also in GDX (the graphics will continue to retain their references, so whether you execute Gdx.graphics.getGL10 or GDX.GL10, you are actually calling the same static variable). In fact, if you want to run LIBGDX without using GDX, then there is no way to think about it other than to refactor the source code.

PS: If you do not know exactly what environment you use LIBGDX, in fact, do not have to be strong gl10 or GL11, The default encapsulation for OpenGL interfaces in Libgdx can be called by GDX.GL (the corresponding version of GL is still required to perform some non-multi-version common interfaces).

Want to use LIBGDX, but do not understand what GDX is for, then everything is empty talk.

I'll start with a detailed explanation of the image processing and Game Components section in LIBGDX:
Mesh:

Essentially, all 3D objects that are visible in the Libgdx are first a mesh (grid, or high-level primitives in three-dimensional grids). How mesh is generated. As we all know, the three-dimensional geometry of mathematics is composed of dots, lines, and polygons, no matter how complex the image can be decomposed into countless small three parts, or can be composed of a very basic n these three parts; when 3D game development, when we want to build complex 3D images, First, these specific points, lines, and triangles are formed by a series of ordered vertices (vertices), that is, the drawing primitives (primitives), and the basic elements are combined into a more complete high-level entity, which is a specific 3D object. Therefore, if the mesh concept of a simple understanding, in fact, it is a symbol of the complete image of the basic elements of the body, LIBGDX first let us make a subdivision of the vertices to form the basic elements, and then by the mesh class will be the basic elements of the more complex to display the advanced elements.

The Returntomarchfeld example provided by the LIBGDX author is visible, and the basic effect is as shown in the following figure:



Texture:

LIBGDX provides a game texture class, which is essentially understood as an image stored in video memory, which is mapped to display the image on the game's interface via OpenGL. The LIBGDX texture can be loaded directly from the specified file path, or it can be created from the Pixmap class provided by it (its texture (int width, int height, format format) constructs a direct call to Pixmap, Not have to be injected externally after generating pixmap). In addition, when loading texture, the individual recommends texturedict.loadtexture function calls through LIBGDX, which provides texture cache management internally to avoid repetitive loading of meaningless resources. In addition, texture will usually be used with the Textureregion class, the use of textureregion packaging texture, and then use SpriteBatch to draw, it is convenient to revise texture for the display range we need. Also, the Sprite class in Libgdx is the textureregion subclass, so it is possible to use the sprite as a textureregion, but the sprite analogy Textureregion expanded. However, LIBGDX's Spritecache class does not inherit the sprite or the textureregion, so it does not play the role of textureregion, it can only build a set of static mapping, it is hereby explained.

LIBGDX texture and Sprite use public class Main extends Androidapplication {class Testsprite implements APPLICATIONL  
        Istener {//Prepare drawing with SpriteBatch SpriteBatch SpriteBatch;  
        Prepare the game sprite sprite sprite;  
        Prepare picture loading with Texture Texture Texture;  
            public void Create () {//build SpriteBatch SpriteBatch = new SpriteBatch (); To build the texture, the image width and height must be equal to 2 of the whole number of powers, otherwise the exception//PS: In the Android environment using LIBGDX internal load must file must be located in the assets directory Te  
            Xture = new Texture (Gdx.files.internal ("mysprite.png"));  
            Constructs a sprite sprite = new Sprite (texture) with the specified texture;  
        Positioning to the 0, the (libgdx using standard Cartesian coordinate system, starting from the bottom of the lower 0) sprite.setposition (100, 180);  
            } public void Render () {//Clear screen Gdx.gl.glClear (gl10.gl_color_buffer_bit);  
            Initialize the drawing call Spritebatch.begin ();  
         Draw sprites to the game screen   Sprite.draw (SpriteBatch);  
        End Drawing call Spritebatch.end ();  
            public void Dispose () {//frees the resource occupied by Spritebatch.dispose ();  
        Texture.dispose (); } public void Resume () {} public void Pause () {} public void resize (in  
        t width, int height) {}} public void OnCreate (bundle bundle) {super.oncreate (bundle);  
        Initialize the game screen and set whether Gles 2.0 is supported, if you have no need to select true for backwards compatibility (2.1 or more), otherwise choose false.  
    Initialize (new Testsprite (), true);   }  
}

Pixmap:

LIBGDX provides a class of pixel-level image rendering, because LIBGDX currently has an image decoder in JNI mode, so we can directly understand Pixmap as a bitmap in Android, the implementation of the details of the difference between the two, but the specific role is similar. Pixmap supports the alpha, Luminancealpha, RGB565, RGBA4444, RGB888, RGBA8888 and other five image color modes, supporting the reading and loading of three image files such as PNG, JPG and BMP. In general, Pixmap must be mixed with texture to actually display the screen. But in fact, LIBGDX's texture has built-in pixmap.


LIBGDX Author Blog: http://www.badlogicgames.com/

LIBGDX Project Address: http://code.google.com/p/libgdx/


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.