已閱讀5頁(yè),還剩9頁(yè)未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
Texture(紋理)public class HelloWorld implements ApplicationListener public SpriteBatch batch; / 聲明紋理 public Texture texture; public Sprite sprite; Override public void create() batch = new SpriteBatch(); / 實(shí)例化texture texture = new Texture(Gernal(data/Potato.jpg); public void render() Gdx.gl.glClearColor(1, 1, 1, 1);/ 設(shè)置背景為白色 Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);/ 清屏 batch.begin(); batch.draw(texture, 0, 0, 480, 320); batch.end(); SpriteBatch類(lèi)(SpriteBatch就是一個(gè)畫(huà)筆)首先聲明類(lèi)名,實(shí)例化、在繪制的的時(shí)候分三步,必須先調(diào)用begin()方法,然后再調(diào)用draw()方法,最后畫(huà)完了調(diào)用end()結(jié)束。public class HelloWorld implements ApplicationListener public SpriteBatch batch; / 聲明紋理 public Texture texture; public Sprite sprite; public void create() batch = new SpriteBatch(); / 實(shí)例化texture texture = new Texture(Gernal(data/Potato.jpg); public void render() Gdx.gl.glClearColor(1, 1, 1, 1);/ 設(shè)置背景為白色 Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);/ 清屏 batch.begin(); batch.draw(texture, 0, 0, 480, 320); batch.end(); TextureRegion 類(lèi)(截圖工具)public class HelloWorld implements ApplicationListener public SpriteBatch batch; / 聲明紋理 public Texture texture; public TextureRegion textureRegion; public Sprite sprite; public void create() batch = new SpriteBatch(); / 實(shí)例化texture texture = new Texture(Gernal(data/Potato.jpg); textureRegion = new TextureRegion(texture, 0, 0, 512, 512); / textureRegion = new TextureRegion(texture, 512, 512, -512, / -512);-反方向截圖 public void dispose() batch.dispose(); texture.dispose(); public void render() Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); batch.begin(); / batch.draw(texture, 0, 0, 480, 320); batch.draw(textureRegion, 0, 0, 480, 320); batch.end(); Sprite類(lèi)public class HelloWorld implements ApplicationListener public SpriteBatch batch; / 聲明紋理 public Texture texture; public Sprite sprite; public void create() batch = new SpriteBatch(); / 實(shí)例化texture texture = new Texture(Gernal(data/Potato.jpg); TextureRegion region = new TextureRegion(texture, 512, 0, 512, 512); sprite = new Sprite(region); sprite.setSize(120, 120);/ 設(shè)置繪制的大小,為了方便我們?cè)O(shè)置的120,120,小一點(diǎn)方便查看 sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2);/ 設(shè)置旋轉(zhuǎn)的中心點(diǎn),咱們就設(shè)置為屏幕的中心點(diǎn) sprite.setRotation(50);/ 這個(gè)是以上面設(shè)置的中心點(diǎn)為中心,旋轉(zhuǎn)一定角度的設(shè)置 sprite.setPosition(150, 110);/ 起始位置設(shè)置為中心區(qū)域附近(150,110) sprite.setColor(1, 0, 1, 1);/ 顏色就設(shè)置為粉色吧 public void render() Gdx.gl.glClearColor(1, 1, 1, 1);/ 設(shè)置背景顏色為白色 Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);/ 清屏 batch.begin(); sprite.draw(batch); batch.end(); BitmapFont類(lèi)public class HelloWorld implements ApplicationListener public SpriteBatch batch; BitmapFont font; public void create() font = new BitmapFont(Gernal(data/Potato.fnt), Gernal(data/Potato.png), false); / font.setColor(0.5f,0.4f,0.6f,1);/設(shè)置顏色 / / font.setScale(1.0f);/字體比例大小 batch = new SpriteBatch(); Override public void render() Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); batch.begin(); font.draw(batch, -奮斗小土豆丶, 200, 160); font.drawMultiLine(batch, 愛(ài)情來(lái)得快,去的也快,n只有豬肉卷是永恒的, Gdx.graphics.getWidth() / 5, 0.8f * Gdx.graphics.getHeight(); batch.end(); Animation類(lèi)Animation walkAnimation = new Animation(float fDuration, keyFrames)(1)TextureRegion數(shù)組代碼:TextureRegion tmp = TextureRegion.split(walkSheet, walkSheet.getWidth() / FRAME_COLS, walkSheet.getHeight() /FRAME_ROWS);這個(gè)段代碼是怎么回事呢?他是采用分離式的方法分分割傳入的紋理,將獲得的紋理分為一個(gè)二維數(shù)組。記住,前提是分割的矩形大小相等。然后使用臨時(shí)變量,填充walkframes數(shù)組。這是樣使用起來(lái)很方便。NORMAL:這個(gè)不用說(shuō)了,就是正常的播放模式。REVERSED:反向播放,從后向前播放,這個(gè)就像人物倒退的跑。LOOP:持續(xù)播放,這個(gè)比較常用。LOOP_REVERSED:持續(xù)倒退播放。LOOP_PINGPONG: 向前播放幾張圖片,再向后播放幾幀圖片 代碼stateTime += Gdx.graphics.getDeltaTime(),他是一個(gè)獲取一個(gè)狀態(tài)下所持續(xù)的一個(gè)時(shí)間。就像我們?cè)诂F(xiàn)實(shí)世界使用的時(shí)間一樣,一般配合系統(tǒng)時(shí)間使用Gdx.graphics.getDeltaTime():獲取系統(tǒng)渲染時(shí)間,一般默認(rèn)是0.173秒。 public class Map implements ApplicationListener private static final int FRAME_COLS = 6; private static final int FRAME_ROWS = 5; Animation walkAnimation; Texture walkSheet; TextureRegion walkFrames; SpriteBatch batch; TextureRegion currentFrame; float stateTime; Override public void create() walkSheet = new Texture(Gernal(animation_sheet.png); TextureRegion tmp = TextureRegion.split(walkSheet, walkSheet.getWidth() / FRAME_COLS, walkSheet.getHeight() / FRAME_ROWS); walkFrames = new TextureRegionFRAME_COLS * FRAME_ROWS; int index = 0; for (int i = 0; i FRAME_ROWS; i+) for (int j = 0; j FRAME_COLS; j+) walkFramesindex+ = tmpij; walkAnimation = new Animation(0.025f, walkFrames); walkAnimation.setPlayMode(walkAnimation.LOOP_PINGPONG); batch = new SpriteBatch(); stateTime = 0f; public void render() Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); stateTime += Gdx.graphics.getDeltaTime(); currentFrame = walkAnimation.getKeyFrame(stateTime, true); batch.begin(); batch.draw(currentFrame, Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2); batch.end(); Image控件(圖片) Image(Texture texture) 和 Image(TextureRegion region)public class MyGdxGame implements ApplicationListener Stage stage; Image VictoriaImage; TextureRegion region; Texture tex; public void create() tex = new Texture(Gernal(data/1.png); region = new TextureRegion(tex, 0, 0, 512, 512); VictoriaImage = new Image(region); VictoriaImage.setColor(Color.PINK);/顏色 VictoriaImage.setScale(0.5F);/縮放比例 VictoriaImage.setPosition(230, 40);/繪畫(huà)起點(diǎn) VictoriaImage.setOrigin(0, 0);/ 設(shè)置旋轉(zhuǎn)中心 VictoriaImage.setRotation(45);/旋轉(zhuǎn)中心 VictoriaImage.setSize(390, 300);/繪畫(huà)大小 stage = new Stage(480, 320, false); Gdx.input.setInputProcessor(stage); stage.addActor(VictoriaImage); public void render() Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); stage.act(); stage.draw(); 按鈕(Button)ImageButton(Drawable imageUp, Drawable imageDown, Drawable imageChecked) ImageButton(Skin skin) public class MyGdxGame implements ApplicationListener Stage stage; TextureRegionDrawable up; TextureRegionDrawable down; TextureRegion buttonUp; TextureRegion buttonDown; Texture tex; ImageButton button; public void create() tex = new Texture(Gernal(data/control.png); TextureRegion tmp = TextureRegion.split(tex, 120, 120); buttonUp = tmp00; buttonDown = tmp01; up = new TextureRegionDrawable(buttonUp); down = new TextureRegionDrawable(buttonDown); button = new ImageButton(up, down); button.setPosition(100, 100); stage = new Stage(480, 320, false); Gdx.input.setInputProcessor(stage); stage.addActor(button); public void render() Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); stage.act(); stage.draw(); Actor類(lèi)(演員)public class mario extends Actor public static float x;public static float y;public static float statetime;Texture texture;TextureRegion currentFrame;ImageButton buttonL;ImageButton buttonR;Animation aniRight;Animation aniLeft;Animation aniIdle;public static int LeftState = 1;public static int IdeltState = 2;public static int RightState = 3;public static int state = 2;public mario(float x, float y) this.x = x;this.y = y;this.show();public void show() texture = new Texture(Gernal(data/mario.png);TextureRegion spilt = TextureRegion.split(texture, 64, 64);TextureRegion miror = TextureRegion.split(texture, 64, 64);for (TextureRegion region1 : miror) for (TextureRegion region2 : region1) region2.flip(true, false);/ 右TextureRegion regionR = new TextureRegion3;regionR0 = spilt01;regionR1 = spilt02;regionR2 = spilt00;aniRight = new Animation(0.1f, regionR);/ 左TextureRegion regionL = new TextureRegion3;regionL0 = miror01;regionL1 = miror02;regionL2 = miror00;aniLeft = new Animation(0.1f, regionL);/ 空閑TextureRegion regionI = new TextureRegion1;regionI0 = spilt00;aniIdle = new Animation(0.1f, regionI);buttonL = new ImageButton(new TextureRegionDrawable(spilt10),new TextureRegionDrawable(spilt11);buttonR = new ImageButton(new TextureRegionDrawable(miror10),new TextureRegionDrawable(miror11);buttonL.setPosition(20, 20);buttonR.setPosition(200, 20);buttonL.addListener(new InputListener() public void touchUp(InputEvent event, float x, float y,int pointer, int button) state = IdeltState;super.touchUp(event, x, y, pointer, button);public boolean touchDown(InputEvent event, float x, float y,int pointer, int button) state = LeftState;return true;);buttonR.addListener(new InputListener() public void touchUp(InputEvent event, float x, float y,int pointer, int button) / TODO Auto-generated method stubstate = IdeltState;super.touchUp(event, x, y, pointer, button);public boolean touchDown(InputEvent event, float x, float y,int pointer, int button) / TODO Auto-generated method stubstate = RightState;return true;);public void update()if(state = LeftState)this.x -=1.5f;if(x400) this.x = 400;this.x = x;public void aniCheck()if(state = LeftState)currentFrame = aniLeft.getKeyFrame(statetime, true);else if(state = RightState)currentFrame = aniRight.getKeyFrame(statetime, true);else if (state = IdeltState) currentFrame = aniIdle.getKeyFrame(statetime,true);public void draw(SpriteBatch batch, float parentAlpha) statetime+=Gdx.graphics.getDeltaTime();this.update();this.aniCheck();batch.draw(currentFrame, x, y);public void act(float delta) / TODO Auto-generated method stubsuper.act(delta);public class MyGdxGame implements ApplicationListener Stage stage; Mario mario; Image image; Override public void create() image = new Image(new Texture(Gernal(data/13.jpg); image.setPosition(0, 170); stage = new Stage(480, 320, false); mario = new Mario(100, 190); Gdx.input.setInputProcessor(stage); stage.addActor(image); stage.addActor(mario); stage.addActor(mario.buttonL); stage.addActor(mario.buttonR); Override public void render() Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); stage.act(); stage.draw();Stage(舞臺(tái))一個(gè)Stage必須負(fù)責(zé)接收輸入事件,同時(shí)將它分配給演員。這通常是通過(guò)Stage的gdx.input.setinputprocessor來(lái)實(shí)現(xiàn)。Stage(float width, float height, boolean keepAspectRatio, SpriteBatch batch)public class MyGame implements ApplicationListener GameStage gameStage; StartStage startStage; StoreStage storeStage; public void create() gameStage = new GameStage(); startStage = new StartStage(); storeStage = new StoreStage(); public void selectStageRender() if(Constants.Stageflag = Constants.StartStageOn) Gdx.input.setInputProcessor(startStage); startStage.act(); startStage.draw(); else if (Constants.Stageflag = Constants.GameStageOn) Gdx.input.setInputProcessor(gameStage); gameStage.act(); gameStage.draw(); else if (Constants.Stageflag = Constants.StoreStageOn) Gdx.input.setInputProcessor(storeStage); storeStage.act(); storeStage.draw(); public void render() Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); selectStageRender(); public class StartStage extends Stage Texture texture; TextureRegion startRegion; Image startImage; Image newGameBtn; TextureRegion new
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024學(xué)校實(shí)驗(yàn)室設(shè)備更新及維修服務(wù)合同3篇
- 2024店鋪轉(zhuǎn)讓協(xié)議書(shū)
- 2024模具智能制造技術(shù)研發(fā)合同
- 2024標(biāo)準(zhǔn)版兩居室房車(chē)短期租賃合同版
- 2024服裝工裝定制合同
- 2024青島運(yùn)動(dòng)會(huì)官方用車(chē)租賃服務(wù)協(xié)議3篇
- 2024年行車(chē)設(shè)備安裝與維護(hù)合同3篇
- 2024年版城市供水項(xiàng)目特許經(jīng)營(yíng)權(quán)協(xié)議
- 2024運(yùn)營(yíng)總監(jiān)國(guó)際業(yè)務(wù)拓展與跨國(guó)合作合同3篇
- 2025年度網(wǎng)絡(luò)安全技術(shù)股權(quán)合作與轉(zhuǎn)讓合同3篇
- 配件供應(yīng)技術(shù)服務(wù)和質(zhì)保期服務(wù)計(jì)劃方案
- 中藥房培訓(xùn)課題
- 供電方案審批流程
- 球墨鑄鐵管行業(yè)分析及市場(chǎng)研究報(bào)告
- 市政道路改造施工合理化建議
- 2024年廣東省廣州城投投資有限有限公司招聘筆試參考題庫(kù)含答案解析
- 2024中國(guó)出口信用保險(xiǎn)公司江蘇分公司勞務(wù)派遣人員招聘筆試參考題庫(kù)附帶答案詳解
- 自然情懷-主題作文訓(xùn)練
- 智能智能化智能眼鏡
- 三年級(jí)下冊(cè)數(shù)學(xué)混合計(jì)算100題及答案
- 社會(huì)工作專(zhuān)業(yè)見(jiàn)習(xí)教學(xué)大綱
評(píng)論
0/150
提交評(píng)論