Actions of Actors in libgdx(libgdx 中 Actor 的操作)
问题描述
我已经制作了我的 演员,但我不清楚如何利用 action
和 act
方法.除了基本的 Javadoc,我还没有找到关于这些方法的好的教程.
I have made my Actor, but I am unclear on how to take advantage of the action
and act
methods. Outside of the basic Javadoc, I have not found a good tutorials on these methods.
任何人都可以提供一个示例,对演员的操作进行评论吗?
Can anyone provide an example with comments for actions on actors?
推荐答案
由于 LibGDX 的变化,此答案已过时.有关最新文档,请参阅 scene2d wiki 页面.
LibGDX 中有多种可用的操作可供您使用.它们在 com.badlogic.gdx.scenes.scene2d.actions
包中.我会说有3种动作:
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:
- 动画动作
- 复合动作
- 其他操作
动画动作会修改演员的各种属性,例如位置、旋转、缩放和 alpha.它们是:
Animation actions modify various properties of your actor, such as location, rotation, scale and alpha. They are:
- FadeIn - 将演员的 alpha 从演员的当前 alpha 更改为 1
- FadeOut - 将演员的 alpha 从演员的当前 alpha 更改为 0
- FadeTo - 将演员的 alpha 从演员的当前 alpha 更改为特定值
- MoveBy - 移动你的演员特定数量
- MoveTo - 将您的演员移动到特定位置
- RotateBy - 将你的演员旋转特定角度
- RotateTo - 将你的演员旋转到特定角度
- ScaleTo - 将您的演员缩放到特定的比例因子
- 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:
- 并行 - 并行执行给定的操作 - 一次执行所有操作
- 顺序 - 按顺序执行给定的操作 - 一个接一个
其他操作:
- 重复 - 重复给定动作 n 次
- 永远 - 永远重复给定的动作
- 延迟 - 将给定操作的执行延迟特定的时间量
- Remove - 从舞台中移除给定的 Actor
每个动作都有一个静态方法 $
来创建该动作的实例.创建动画动作示例:
Every action has a static method $
which creates instance of that Action.
Example of creating animation actions:
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
创建更复杂动作序列的示例:
Example of creating more complex action sequence:
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
);
动画动作也可以让你指定Interpolator
.有多种实现方式:
Animation actions also let you specify Interpolator
. There are various implementations:
- AccelerateDecelerateInterpolator
- AccelerateInterpolator
- AnticipateInterpolator
- DecelerateInterpolator
- 线性插值器
- 过冲插值器
插值器 Javadoc:插值器定义动画的变化率.这允许加速、减速等基本动画效果(alpha、缩放、平移、旋转).将插值器设置为您的操作:
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);
要在舞台上实际执行为演员定义的所有动作,您必须在渲染方法中调用 stage.act(...):
To actually execute all actions defined for actors on stage, you have to call stage.act(...) in your render method:
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
这篇关于libgdx 中 Actor 的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:libgdx 中 Actor 的操作
基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01