libgdx 中 Actor 的操作

Actions of Actors in libgdx(libgdx 中 Actor 的操作)
本文介绍了libgdx 中 Actor 的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经制作了我的 演员,但我不清楚如何利用 actionact 方法.除了基本的 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:

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

动画动作会修改演员的各种属性,例如位置、旋转、缩放和 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 的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
iOS: Send multiple actions to a bar button(IOS:向一个栏按钮发送多个动作)
How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)