日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Android游戲引擎libgdx使用教程6:演員與演出

上一節(jié)講了常用UI類和舞臺(tái),本節(jié)我們已經(jīng)能夠很容易的制作一出戲了。

創(chuàng)新互聯(lián)從2013年開始,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站設(shè)計(jì)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元米林做網(wǎng)站,已為上家服務(wù),為米林各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:18982081108

因?yàn)閍ctor類在繪制是以x、y值為基準(zhǔn),所以我們可以通過(guò)控制x、y值變化演員的位置,但是演員的其他效果需要配合Action類進(jìn)行操作。

Action類是一個(gè)抽象類,所有的具體實(shí)現(xiàn)都在com.badlogic.gdx.scenes.scene2d.actions包中。

而包中的類依功能而言可以分為兩類:

1、控制Action
2、表現(xiàn)Action

控制Action沒(méi)有直接表現(xiàn)效果,它操作的對(duì)象是表現(xiàn)Action。比如Delay。

表現(xiàn)Action就是直接的表現(xiàn)效果,繼承自AnimationAction,操作對(duì)象是Actor。比如MoveTo。

現(xiàn)在挨著說(shuō)吧:

控制類:

Delay $ (Action action, float duration)

延遲duration秒執(zhí)行action。

Forever $ (Action action)

 一直執(zhí)行action。

Parallel $ (Action... actions)

并行(同時(shí))執(zhí)行actions。

Repeat $ (Action action, int times)

重復(fù)action times次。

Sequence $ (Action... actions)

按順序執(zhí)行actions。

Remove $ ()

刪除所有Action。

表現(xiàn)類:

FadeIn $ (float duration) FadeOut $ (float duration)

淡入淡出效果

FadeTo $ (float alpha, float duration)

duration秒改變至alpha。

MoveTo $ (float x, float y, float duration) MoveBy $ (float x, float y, float duration)

用duration移動(dòng)到x,y處。

RotateBy $ (float rotation, float duration) RotateTo $ (float rotation, float duration)

用duration秒旋轉(zhuǎn)rotation度。

ScaleTo $ (float scaleX, float scaleY, float duration)

縮放x到scaleX,y到scaleY,用時(shí)duration秒。

實(shí)例演示

一個(gè)個(gè)寫例子太麻煩了,而且實(shí)際運(yùn)用中也多是多個(gè)組合運(yùn)用,下面來(lái)看一個(gè)綜合性的示例:

我們的主角是

通過(guò)action的組合實(shí)現(xiàn)閃爍,飛動(dòng),旋轉(zhuǎn)等效果。

代碼如下:

 
 
 
 
  1. package com.cnblogs.htynkn.listener;     
  2. import com.badlogic.gdx.ApplicationListener;     
  3. import com.badlogic.gdx.Gdx;     
  4. import com.badlogic.gdx.graphics.GL10;     
  5. import com.badlogic.gdx.graphics.Texture;     
  6. import com.badlogic.gdx.graphics.Texture.TextureFilter;     
  7. import com.badlogic.gdx.math.MathUtils;     
  8. import com.badlogic.gdx.scenes.scene2d.Action;     
  9. import com.badlogic.gdx.scenes.scene2d.Stage;     
  10. import com.badlogic.gdx.scenes.scene2d.actions.FadeIn;     
  11. import com.badlogic.gdx.scenes.scene2d.actions.FadeOut;     
  12. import com.badlogic.gdx.scenes.scene2d.actions.MoveBy;     
  13. import com.badlogic.gdx.scenes.scene2d.actions.MoveTo;     
  14. import com.badlogic.gdx.scenes.scene2d.actions.Parallel;     
  15. import com.badlogic.gdx.scenes.scene2d.actions.Repeat;     
  16. import com.badlogic.gdx.scenes.scene2d.actions.RotateTo;     
  17. import com.badlogic.gdx.scenes.scene2d.actions.Sequence;     
  18. import com.badlogic.gdx.scenes.scene2d.actors.Image;     
  19. public class FirstGame implements ApplicationListener {     
  20. private Stage stage;     
  21. private Texture texture;     
  22. @Override     
  23. public void create() {     
  24. stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),     
  25. true);     
  26. texture = new Texture(Gdx.files.internal("star.png"));     
  27. texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);     
  28. float duration = 4f;     
  29. int maxwidth = Gdx.graphics.getWidth() - texture.getWidth();     
  30. int maxheight = Gdx.graphics.getHeight() - texture.getHeight();     
  31. for (int i = 0; i < 20; i++) {     
  32. Image image = new Image("star" + i, texture);     
  33. image.x = MathUtils.random(0, maxwidth);     
  34. image.y = MathUtils.random(0, Gdx.graphics.getHeight()); //隨機(jī)出現(xiàn)     
  35. Action moveAction = Sequence.$(MoveTo.$(MathUtils.random(0,     
  36. maxwidth), MathUtils.random(0, maxheight), duration / 2),     
  37. MoveBy.$(MathUtils.random(0, maxwidth), MathUtils.random(0,     
  38. maxheight), duration / 2)); //移動(dòng)方向和地點(diǎn)隨機(jī)     
  39. Action rotateAction = RotateTo.$(360, duration); //旋轉(zhuǎn)     
  40. Action fadeAction = Repeat.$(Sequence.$(FadeOut.$(duration / 20),     
  41. FadeIn.$(duration / 20)), 10); //閃爍,重復(fù)10次     
  42. image.action(Parallel.$(moveAction, rotateAction, fadeAction)); //所有action并行     
  43. stage.addActor(image);     
  44. }     
  45. Gdx.input.setInputProcessor(stage);     
  46. }     
  47. @Override     
  48. public void dispose() {     
  49. texture.dispose();     
  50. stage.dispose();     
  51. }     
  52. @Override     
  53. public void pause() {     
  54. // TODO Auto-generated method stub     
  55. }     
  56. @Override     
  57. public void render() {     
  58. Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);     
  59. stage.act(Gdx.graphics.getDeltaTime());     
  60. stage.draw();     
  61. }     
  62. @Override     
  63. public void resize(int width, int height) {     
  64. // TODO Auto-generated method stub     
  65. }     
  66. @Override     
  67. public void resume() {     
  68. // TODO Auto-generated method stub     
  69. }     
  70. }   

其實(shí)每個(gè)action的用法都很簡(jiǎn)單,主要問(wèn)題是怎么組合排列來(lái)顯示一種符合需求的效果。

我發(fā)現(xiàn)libgdx的更新不是一般快,每天都有幾個(gè)版本的。那個(gè)通過(guò)文件配置UI樣式讓我覺(jué)得非常有意思,但是具體操作中有諸多問(wèn)題。


當(dāng)前名稱:Android游戲引擎libgdx使用教程6:演員與演出
本文地址:http://www.dlmjj.cn/article/dhdggjh.html