Use of the android game development framework libgdx (6)-actors and performances

Source: Internet
Author: User
Tags libgdx

The libgdx used in this article is version 0.92, which may be different from the latest version. The full text is for reference only.

In the previous article, we talked about the UI and the stage. Now we can easily build a project.

Because the actor class is drawn based on the x and y values, we can change the actor position by controlling the x and y values. However, other actor effects must be operated with the action class.

The action class is an abstract class. All specific implementations are in the com. badlogic. GDX. Scenes. scene2d. Actions package.

The classes in the package can be divided into two categories by function:

    1. Control Action
    2. Action

The control action does not directly show the effect. The object it operates on is the action.

For example, delay.

The action represents the direct expression effect, inherited from the animationaction, and the operation object is the actor.

For example, moveTo.

Let's talk about it now:

Control class:

 
Delay $ (Action action, float duration)

The execution of the action is delayed in duration seconds.

 
Forever $ (action Action)

Always execute action.

Parallel $ (action... Actions)

Execute actions concurrently.

 
Repeat $ (Action action, int times)

Repeat the action times.

 
Sequence $ (action... Actions)

Perform actions in sequence.

Remove $ ()

Delete all actions.

Presentation class:

 
Fadein $ (float duration) fadeout $ (float duration)

Fade in and fade out

 
Fadeto $ (float Alpha, float duration)

The duration seconds are changed to Alpha.

 
MoveTo $ (float X, float y, float duration) moveBy $ (float X, float y, float duration)

Use duration to move to X and Y.

 
Rotateby $ (float rotation, float duration) rotateto $ (float rotation, float duration)

Rotate rotation in duration seconds.

Scaleto $ (float scalex, float scaley, float duration)

Scales X to scalex, and Y to scaley in duration seconds.

Writing examples one by one is too troublesome, and many examples are used in combination. The following is a comprehensive example:

Our main character is

The combination of actions enables flickering, flying, and rotating effects.

CodeAs follows:

Package COM. cnblogs. htynkn. listener; import COM. badlogic. GDX. applicationlistener; import COM. badlogic. GDX. GDX; import COM. badlogic. GDX. graphics. gl10; import COM. badlogic. GDX. graphics. texture; import COM. badlogic. GDX. graphics. texture. texturefilter; import COM. badlogic. GDX. math. mathutils; import COM. badlogic. GDX. scenes. scene2d. action; import COM. badlogic. GDX. scenes. scene2d. stage; import COM. badlogic. GDX. scenes. scene2d. actions. fadein; import COM. badlogic. GDX. scenes. scene2d. actions. fadeout; import COM. badlogic. GDX. scenes. scene2d. actions. moveBy; import COM. badlogic. GDX. scenes. scene2d. actions. moveTo; import COM. badlogic. GDX. scenes. scene2d. actions. parallel; import COM. badlogic. GDX. scenes. scene2d. actions. repeat; import COM. badlogic. GDX. scenes. scene2d. actions. rotateto; import COM. badlogic. GDX. scenes. scene2d. actions. sequence; import COM. badlogic. GDX. scenes. scene2d. actors. image; public class firstgame implements applicationlistener {private stage; private texture; @ override public void create () {stage = new stage (GDX. graphics. getwidth (), GDX. graphics. getheight (), true); texture = new texture (GDX. files. internal ("star.png"); texture. setfilter (texturefilter. linear, texturefilter. linear); float duration = 4f; int maxwidth = GDX. graphics. getwidth ()-texture. getwidth (); int maxheight = GDX. graphics. getheight ()-texture. getheight (); For (INT I = 0; I <20; I ++) {image = new image ("star" + I, texture); image. X = mathutils. random (0, maxwidth); image. y = mathutils. random (0, GDX. graphics. getheight (); // action moveaction = sequence. $ (moveTo. $ (mathutils. random (0, maxwidth), mathutils. random (0, maxheight), duration/2), moveBy. $ (mathutils. random (0, maxwidth), mathutils. random (0, maxheight), duration/2); // random action rotateaction = rotateto. $ (360, duration); // rotate action fadeaction = repeat. $ (sequence. $ (fadeout. $ (duration/20), fadein. $ (duration/20), 10); // flickering, Repeat 10 times image. action (parallel. $ (moveaction, rotateaction, fadeaction); // all actions in parallel stage. addactor (image);} GDX. input. setinputprocessor (stage) ;}@ override public void dispose () {texture. dispose (); stage. dispose () ;}@ override public void pause () {// todo auto-generated method stub} @ override public void render () {GDX. GL. glclear (gl10.gl _ color_buffer_bit); stage. act (GDX. graphics. getdeltatime (); stage. draw () ;}@ override public void resize (INT width, int height) {// todo auto-generated method stub} @ override public void resume () {// todo auto-generated method stub }}

Effect (the image is a little big... and so on ):

In fact, the usage of each action is very simple. The main problem is how to combine and arrange to display a desired effect.

I found that libgdx updates are not generally fast, and several versions are available every day. I think it is very interesting to configure the UI style through the file, but there are many problems in the specific operation.

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.