-
Notifications
You must be signed in to change notification settings - Fork 0
Actions
credits All credits for this goes to Ludevik. He wrote up a wonderful tutorial over at stack overflow http://stackoverflow.com/questions/9131554/actions-of-actors-in-libgdx
I though it would be better to have on the official wiki
There are various available actions in LibGDX ready for you. They are in com.badlogic.gdx.scenes.scene2d.actions package. I would say that there are 3 kinds of actions:
Animation actions modify various properties of your actor, such as location, rotation, scale and alpha. They are:
* action * | * description * |
---|---|
* FadeIn * | changes alpha of your actor from actor's current alpha to 1 |
* FadeOut * | changes alpha of your actor from actor's current alpha to 0 |
* FadeTo * | changes alpha of your actor from actor's current alpha to specific value |
* MoveBy * | moves your actor by specific amount |
* MoveTo * | moves your actor to specific location |
* RotateBy * | rotates your actor by specific angle |
* RotateTo * | rotates your actor to specific angle |
* ScaleTo * | scales your actor to specific scale factor |
Composite actions combine multiple actions in one action, there are:
* action * | * description * |
---|---|
* Parallel * | execute given actions in parallel - all actions at once |
* Sequence * | execute given actions in sequence - one after another |
These should be fairly self explainatory.
* action * | * description * |
---|---|
* Repeat * | repeats given action n-times |
* Forever * | repeats given action forever |
* Delay * | delays execution of given action for specific amount of time |
* Remove * | removes given Actor from stage |
**Every action has a static method $ which creates instance of that Action. **
MoveTo move = MoveTo.$(200, 200, 0.5f); //move Actor to location (200,200) in 0.5 s
RotateTo rotate = RotateTo.$(60, 0.5f); //rotate Actor to angle 60 in 0.5 s
Sequence sequence = Sequence.$(
MoveTo.$(200, 200, 0.5f), //move actor to 200,200
RotateTo.$(90, 0.5f), //rotate actor to 90°
FadeOut.$(0.5f), //fade out actor (change alpha to 0)
Remove.$() //remove actor from stage
);
Animation actions also let you specify Interpolator. There are various implementations:
- AccelerateDecelerateInterpolator
- AccelerateInterpolator
- AnticipateInterpolator
- DecelerateInterpolator
- LinearInterpolator
- OvershootInterpolator
Interpolator Javadoc: An interpolator defines the rate of change of an animation. This allows the basic animation effects (alpha, scale, translate, rotate) to be accelerated, decelerated etc. To set interpolator to your action
action.setInterpolator(AccelerateDecelerateInterpolator.$());
When you have your action with interpolator ready, then you set that action to your actor:
actor.action(yourAction);
To actually execute all actions defined for actors on stage, you have to call stage.act(...) in your render/update method:
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
-
Developer's Guide
- Introduction
- Goals & Features
- Community & Support
- Contributing
- Games Built with Libgdx
- Prerequisites
- Project Setup, Running & Debugging
- Third Party Services
- Working from Source
- Using libgdx with other JVM languages
- The Application Framework
- A Simple Game
- File Handling
- Preferences
- Input Handling
- Memory Management
- Audio
-
Graphics
- Configuration & Querying Graphics ??
- Fullscreen & VSync
- Continuous & Non-Continuous Rendering
- Clearing the Screen
- OpenGL ES Support * Configuration & Querying OpenGL ?? * Direct Access ?? * Utility Classes * Rendering Shapes * Textures & TextureRegions * Meshes * Shaders * Frame Buffer Objects
- 2D Graphics * SpriteBatch, TextureRegions, and Sprite * Clipping, with the use of ScissorStack * Orthographic camera * Mapping Touch Coordinates ?? * NinePatches * Bitmap Fonts * Distance field fonts * Using TextureAtlases * Pixmaps * Packing Atlases Offline * Packing Atlases at Runtime * 2D Particle Effects * Tile Maps * scene2d * scene2d.ui * Skin
- 3D Graphics ?? * Quick Start * 3D animations and skinning * Importing Blender models in LibGDX * Perspective Camera ?? * Picking ??
- Managing Your Assets
- Utilities
-
Math Utilities
- Interpolation
- Vectors, Matrices, Quaternions
- Circles, Planes, Rays, etc.
- Bounding Volumes ??
- Intersection & Overlap Testing ??
- Physics
- Tools
- Extensions
- gdx-audio ??
- gdx-freetype
- Deploying your Application
- Building Libgdx ??
- Articles
- Deprecated (May be outdated)
- The Application Framework
- The Application Life-cycle ??
- Modules Overview
- File Module
- Graphics Module
- Asset Manager
- Tutorials
- Video Tutorials
- Beginner * Hello World * My First Triangle * Mesh, Color & Texture * Projection, Viewport, & Camera * Creating and texturing 3d models in Blender for Libgdx
- Intermediate * Actions
- Misc * AdMob in Libgdx * Integrating Libgdx and the Device camera * String Builder ??
- The Application Framework