Introduction to Java game engine libgdx

Source: Internet
Author: User
Tags libgdx

1 Preface

Recently I want to do some small applications, but the interface is very non-functional. I naturally want to use the game engine to handle this part of work. I was going to find a good one in flex, but when I found pushbutton, I found that only the goodbye page was left on the official homepage. The message means that everyone is playing mobile now, they gave up the development of this engine. When I saw it, I felt that mobile applications were more promising. Then I went to the image engine developed by android. After comparison, I felt that libgdx looked good, I have studied it for a day. I believe that it can be used to make a good application.

2. What is libgdx?

This class library is developed by badlogic and encapsulates opengl es and box2d engines to run applications on windows, linux, and android. In addition, it is commendable that the author maintains this class library frequently and believes that it will develop faster in the future. Another one has to be mentioned. This author is the developer of Rokon, but he is currently fully engaged in libgdx, and Rokon has not been updated for two years.

The author claims that this is a framework rather than an engine, because it only encapsulates the underlying things and some components on the upper layer need to be developed by themselves. However, I personally feel that the encapsulation is quite good, and most of them are commonly used. The entire framework is very concise and the source code is very easy to read.

Official Address: http://code.google.com/p/libgdx/

3 learning journey 3.1 Environment Construction

Because it is a pure java environment, it is the same as a general project. The official introduction is extremely detailed and will not be described here. Project setup address: http://code.google.com/p/libgdx/wiki/ProjectSetup

3.2 Other preparation work

Do not ignore this part. These work will be very helpful for future study and development.

Note: The following steps need to be done when libgdx0.9.3 is installed. Currently, the libgdx project is directly downloaded in version 0.9.8. These toolkit are included, which is much more convenient than before.

1. Important) download the libgdx source code and its related test and demo. Because it is open source, you can easily obtain these valuable resources, and the source code is clear and easy to read. Svn address: Repository

2. Important) download the gdx dependency project tablelayout, svn address: http://table-layout.googlecode.com/svn/trunk

3. TiledMap editing tool, home address: http://www.mapeditor.org/

4. Texture Pack GUI Texture packaging generation tool, home address: http://code.google.com/p/libgdx-texturepacker-gui/

5. Hiero font editing tools,: http://code.google.com/p/libgdx/downloads/detail? Name = hiero. jar & can = 2 & q =

6. If you want to develop on android, you also need to download the eclipse adt plug-in and android sdk.

3.3 Basic Concepts

Since I have never done similar things before, some things do not have many concepts, which has a great impact on the learning speed. It took me a whole day to make a demo that can control the movements of people...

TextureTexture): an image is called a texture after it is decoded from the original format and uploaded to the GPU. In order to draw texture, ry is often used to describe texture, and vertices corresponding to ry are used to describe texture. For example, to describe a rectangle, you can describe the rectangle by describing each vertex. To draw a graph, you must first bind the texture and then pass a geometric description to OpenGL for painting. The drawing size and position are jointly determined by the geometric description and OpenGL viewport settings.
From: http://www.cnblogs.com/htynkn/archive/2011/11/10/libgdx_2.html)

ActorPerformer): The concept of this item is similar to that of Components in flash. It is an object that can define attribute methods and perform some specific control.

StageStage): it is the place where actor is engaged in activities. There are three elements, one being actor. Of course, there can be many actor on the stage, and the other being Camera, he can scale down and rotate the scenes on the stage. The third is SpriteBatch. This is not a good description. He just sends the content to the GPU in batches, at the same time, collect the information to be drawn for the next screen.

Relationship between each element: The upper-layer container is Application, which controls whether the entire Application runs on android or windows. The second-layer Game is used to manage multiple Screen proxy classes, it can be either displayed or hidden. There are several stages in the scenario, and actors in the stage. An actor on the stage can contain multiple actors. The actor is a group, which is meaningless.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1306144I8-0.jpg "/>

Application Lifecycle:

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1306143128-1.png "/>

3.4 Function Analysis

This system design is really easy to understand, from the perspective of class libraries. If you want to learn more, you should take a closer look at the principles of opengl and box2d.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/130614O29-2.jpg "/>

Assets: class for resource management, mainly responsible for loading related work.

Audio: audio management class, mainly including Music and Sound. The difference is that Music is stream-based, suitable for large files, and Sound is directly loaded in full, suitable for repeated playback.

Files: A Tool class for file operation encapsulation.

Graphics: it encapsulates opengl and implements drawing-related work, such as Texture, Camera, Color, Mesh, TiledMap, and NinePatch.

Input: Events input on the interface. for android, there are gesture events, such as long-pressed and drag-and-drop events.

Math: Mainly graphic computing, such as operations such as matrices, vectors, and rectangles.

Physics. box2d: The encapsulation class of box2d, which has not been carefully viewed yet, can achieve physical effects. For example, gravity and rebound box2d are physical engines. This is an inevitable function ...).

Scene2d: this is the core class of two-dimensional image control. Actor, Stage, and Interpolator interpolation are used to control the animation playback speed. There are three main functions: Action animation, controlling Actor to move, rotate, scale, and so on, and Interpolator to control animation playback, which can accelerate and slow down. Third, ui components, however, there are currently few implementations, such as buttons, images, CheckBox, Label, and ScrollPane.

3.5 first demo

I have an understanding of the whole thing. Of course, I have to make a demo to have a better understanding. I made a very simple demo, that is, clicking on the front and back of the villain, the villain can walk on the map. Because the attachment size limit, so the gdx. jar and gdx-backend-jogl.jar under libs to remove, need to run please add yourself.

Note: If the attachment is located at the bottom of the blog, search for "libgdx-based demo" on the current page if it cannot be found ".

3.6 run the demo as an applet

Since one thing we need to do now must be put into the web page, we naturally need to study how to run in applet mode. The official team gave an introduction, see references 4) For more details. However, I found some problems when I was doing this. I would like to briefly add them.

1. Use the official introduction to finish all the work, but I still cannot run it locally. I use a program as a normal web program, and all the jar files are placed under lib, which is the applet directory in the blog ).
2. Open the java console, that is, the jre/bin/ConsolePanel in your java installation directory. In windows, an icon is automatically displayed in the taskbar in the lower right corner. You can easily view the error when you open the console. We recommend that you open all the debugging parameters in Advanced to see the detailed running process.
3. If the corresponding jars are not found, the downloaded binaries are directly the root directory, which should be the issue of declaring the codebase path on the index.html page. Copy the jar directly to the root directory of the web project to run it. Of course, the actual running should be adjusted to a suitable directory.
4. the strange thing is that my program has no prompt for the client's installation environment, so that it can go to the http://java.sun.com/applets/jdk/1.4/index.htmlpage to access a simple applet demo, which can run normally. Then you can check your page again.
5. In addition, I have read about the problems that need to be adjusted when running linux, that is, the openjdk environment cannot be used. However, it was strange to find that firefox was about to automatically load icetea of openjdk and run chrome In ubuntu.

4. Summary

I have a feeling of finding a gold mine. libgdx is too easy for java developers to get started. It is really convenient to do some desktop and mobile apps, it is also converted into an applet to be placed in the webpage. This class library is also very active in development. I believe it will soon become an essential tool for java Desktop Application developers.

 

References:
1. tutorials: http://code.google.com/p/libgdx/wiki/ProjectSetup
2. Strongly recommend a Chinese blog, in simple words: http://www.cnblogs.com/htynkn/
3. Very good domestic game material site: http://www.66rpg.com/
4. How to make your program run in applet: http://www.thesecretpie.com/2011/05/being-like-minecraft-or-how-to-run-your.html

 

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.