Libgdx framework and main methods (one day you will look back !), Libgdx

Source: Internet
Author: User
Tags libgdx

Libgdx framework and main methods (one day you will look back !), Libgdx
Since zookeeper is a new game engine, he must first understand its framework. The so-called "know yourself and know yourself" means no war! Maybe you didn't feel anything after reading it at the beginning, but believe me, one day you will come back and read it again! I. Application Lifecycle

The game should be efficient and stable, especially for android platforms. The current development is for mobile phones and tablets. It is important to manage resources efficiently. Imagine a game with beautiful production and high playability that runs on your android phone crashes once every 10 seconds. The game stops running like watching cartoons. I can only say, child, don't spoil your mobile games! Haha

The basic lifecycle is as follows:

Image Sharing:


Ii. Game Architecture

I used this framework to learn from others and use it if I think it makes sense.

An application is divided into the following structures:

The input refers to the user's response, which can be Touch, Click, Drag, and so on.

The output is generally an image, sound, image, or effect. Of course, there are files or other data (such as network storage ).

The input files are generally pictures and sounds, and the logic consists of mathematical logic and physical logic.

Libgdx is a Box2D encapsulation for physical processing and can meet general requirements. Some common structures and a small number of formulas are encapsulated in mathematics, but you can develop your own algorithms based on this.

Libgdx can be used directly to process images, sounds, and other files.

Iii. Main methods (important)

These methods are triggered by events in the application declaration cycle, as described below:

Method Name

Description

Create ()

This method is called once when an application is created

Resize (int width, int height)

This method is called every time the game screen resets the size and is not paused. Call once after create ()

The parameter is the new width and height after the screen is reset.

Render ()

This method is called cyclically every time rendering occurs. Game updates occur before rendering. That is to say, first process the logic and then process the rendering.

Pause ()

Call this method before applying destroyed. This method is called when the android mid-range Home Key is pressed or the program is re-entered. In a desktop application, it is called between dispose () when exiting the application.

This is a good place to save the game status. In android, resume () may not be called.

Resume ()

This method is only called in android, and will not be called in desktop applications when the app gets the focus.

Dispose ()

This method is called when destroyed is applied after pause. Note: This method is not called automatically and must be called manually! Among them, AssetManager, BitmapFont, BitmapFontCache, latency, DecalBatch, latency, FrameBuffer, Gdx2DPixmap, IndexArray, IndexBufferObject, IndexBufferObjectSubData, MD5Renderer, Mesh, participant effect, and participant queue tpool. pooledEffect, Pixmap, PixmapPacker, ShaderProgram, SimpleTileAtlas, Skin, SpriteBatch, SpriteCache, Stage, Texture, TextureAtlas, TileAtlas, vertex, VertexArray, VertexBufferObject, VertexBu FferObjectSubData and World must be recycled manually. Therefore, do not forget to recycle them manually. The memory of Android devices is very limited! (Some common ones are marked in green !)

Android generally does not care about resize (). We instantiate the required objects in create and draw them in render. The current flexible data can be maintained during pause. Dispose () Destroys an object. In resume (), the game is restored Based on the maintained data. In fact, it is not responsible. dispose () can be ignored. The android system will automatically recycle some of them, and users will also be able to accept the temporary stagnation after exiting. You can also use the create () method to make it easier to enter a game or initialize a scenario. However, you must take pause () and resume () seriously. Phone calls are the most common type of out-of-the-box interruption. No user prefers a phone call to make the recording or progress disappear.




Is there a good solution to solve the multi-resolution support of libgdx?

1. First make a resolution, then calculate the screen size, and set scaling. 2. stage. Libgdx uses opengl and can be scaled automatically.
 
What do I do according to the "use of android game development framework libgdx (12)" example?

Stage. act (Gdx. graphics. getDeltaTime (); tileMapRenderer. render (c); --------------- error code line stage. draw ();
 

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.