libgdx Action 动作 动画

Libgdx中有个类Actions, 从它开始顺藤摸瓜就能把哪些简单的Action快速掌握

见代码:

 1 public class ActionTestScreen implements Screen,InputProcessor{

 2     private Stage stage;

 3     private Texture texture;

 4     private Image img;

 5 

 6     @Override

 7     public void render(float delta) {

 8         Gdx.gl.glClearColor(1, 0, 0, 1);

 9         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

10         stage.act();

11         stage.draw();

12     }

13 

14     @Override

15     public void show() {

16         Gdx.input.setInputProcessor(this);//容易遗忘

17         stage = new Stage();

18         texture = new Texture("badlogic.jpg");

19         img = new Image(texture);

20         //img.setCenterPosition(img.getWidth()/2,img.getHeight()/2);//重要

21         img.setOrigin(img.getCenterX(),img.getCenterY());//重要!

22         stage.addActor(img);

23         System.out.println(img.getX()+","+img.getY());

24     }

25 

26     @Override

27     public boolean keyDown(int keycode) {

28         switch (keycode){

29             case Input.Keys.NUM_1:{

30                 MoveByAction moveBy = Actions.moveBy(100,100,0.5f);

31                 img.addAction(moveBy);

32                 return true;

33             }

34             case Input.Keys.NUM_2:{

35                 MoveToAction moveTo = Actions.moveTo(200, 200, 0.5f);

36                 img.addAction(moveTo);

37                 return true;

38             }

39             case Input.Keys.NUM_3:{

40                 RotateByAction rotateBy = Actions.rotateBy(90,0.5f);

41                 img.addAction(rotateBy);

42                 return true;

43             }

44             case Input.Keys.NUM_4:{

45                 RotateToAction rotateTo = Actions.rotateTo(90, 0.5f);

46                 img.addAction(rotateTo);

47                 return true;

48             }

49             case Input.Keys.NUM_5:{

50                 ScaleByAction scaleBy = Actions.scaleBy(0.5f,0.5f,0.5f);

51                 img.addAction(scaleBy);

52                 return true;

53             }

54             case Input.Keys.NUM_6:{

55                 ScaleToAction scaleTo = Actions.scaleTo(0.5f,0.5f,0.5f);

56                 img.addAction(scaleTo);

57                 return true;

58             }

59             case Input.Keys.NUM_7:{//顺序执行

60                 img.setCenterPosition(0,0);

61                 img.setScale(1,1);

62 

63                 MoveToAction m2 = Actions.moveTo(200,200,0.5f);

64                 RotateByAction r1 = Actions.rotateBy(360,0.5f);

65                 ScaleToAction s1 = Actions.scaleTo(0.5f,0.5f,0.5f);

66                 SequenceAction s = Actions.sequence(m2,r1,s1);

67                 img.addAction(s);

68                 return true;

69             }

70             case Input.Keys.NUM_8:{//同时执行

71                 img.setCenterPosition(0,0);

72                 img.setScale(1,1);

73 

74                 MoveToAction m2 = Actions.moveTo(200,200,0.5f);

75                 RotateByAction r1 = Actions.rotateBy(360,0.5f);

76                 ScaleToAction s1 = Actions.scaleTo(0.5f,0.5f,0.5f);

77                 ParallelAction s = Actions.parallel(m2,r1,s1);

78                 img.addAction(s);

79                 return true;

80             }

81             case Input.Keys.A:{//同时执行

82                 AlphaAction a1 = Actions.alpha(0.5f,0.5f);

83 

84                 img.addAction(a1);

85                 return true;

86             }

87             ......

88 

89 

90         }

91         return false;

92     }

93 ......

还有一些Action没有列出,用的时候再仔细研究吧,有的我也没搞懂呢

另:Actor貌似没有像2dx那种锚点概念,setPosition总是以左下角为基准??

你可能感兴趣的:(action)