本文介绍了在libgdx演员的动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经作出了演员,但我不清楚如何利用动作的行为方法。基本的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维基页面

This answer is being rendered obsolete because of changes in LibGDX. For up to date documentation see scene2d wiki page.

有在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:

  1. 动画动作
  2. 在复合动作
  3. 其他动作

动画动作修改演员的各种性质,诸如位置,旋转,缩放和α。它们是:

Animation actions modify various properties of your actor, such as location, rotation, scale and alpha. They are:

  • 淡入 - 改变你的演员阿尔法从演员的当前Alpha 1
  • 淡出 - 从演员的当前Alpha改变你的演员阿尔法为0
  • FadeTo - 改变从演员的当前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次
  • 在永 - 给定的动作永远重复
  • 延迟 - 延迟执行的时间具体数额定操作的
  • 删除 - 给演员从舞台

每一个行动有一个静态方法 $ 这将创建一个操作实例。创建动画动作的例子:

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
            );

动画的动作也让你指定插补。有各种实施

  • AccelerateDecelerateInterpolator
  • AccelerateInterpolator
  • AnticipateInterpolator
  • DecelerateInterpolator
  • LinearInterpolator
  • OvershootInterpolator

插补的Javadoc:内插器限定一个动画的变化率。这使得基本的动画效果(α,尺度,平移,旋转)来加速,减速等。要设置插值到你的行动:

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演员的动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 21:46