




已閱讀5頁,還剩9頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
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類(SpriteBatch就是一個畫筆)首先聲明類名,實(shí)例化、在繪制的的時候分三步,必須先調(diào)用begin()方法,然后再調(diào)用draw()方法,最后畫完了調(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 類(截圖工具)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類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è)置繪制的大小,為了方便我們設(shè)置的120,120,小一點(diǎn)方便查看 sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2);/ 設(shè)置旋轉(zhuǎn)的中心點(diǎn),咱們就設(shè)置為屏幕的中心點(diǎn) sprite.setRotation(50);/ 這個是以上面設(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類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, 愛情來得快,去的也快,n只有豬肉卷是永恒的, Gdx.graphics.getWidth() / 5, 0.8f * Gdx.graphics.getHeight(); batch.end(); Animation類Animation walkAnimation = new Animation(float fDuration, keyFrames)(1)TextureRegion數(shù)組代碼:TextureRegion tmp = TextureRegion.split(walkSheet, walkSheet.getWidth() / FRAME_COLS, walkSheet.getHeight() /FRAME_ROWS);這個段代碼是怎么回事呢?他是采用分離式的方法分分割傳入的紋理,將獲得的紋理分為一個二維數(shù)組。記住,前提是分割的矩形大小相等。然后使用臨時變量,填充walkframes數(shù)組。這是樣使用起來很方便。NORMAL:這個不用說了,就是正常的播放模式。REVERSED:反向播放,從后向前播放,這個就像人物倒退的跑。LOOP:持續(xù)播放,這個比較常用。LOOP_REVERSED:持續(xù)倒退播放。LOOP_PINGPONG: 向前播放幾張圖片,再向后播放幾幀圖片 代碼stateTime += Gdx.graphics.getDeltaTime(),他是一個獲取一個狀態(tài)下所持續(xù)的一個時間。就像我們在現(xiàn)實(shí)世界使用的時間一樣,一般配合系統(tǒng)時間使用Gdx.graphics.getDeltaTime():獲取系統(tǒng)渲染時間,一般默認(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);/繪畫起點(diǎn) VictoriaImage.setOrigin(0, 0);/ 設(shè)置旋轉(zhuǎn)中心 VictoriaImage.setRotation(45);/旋轉(zhuǎn)中心 VictoriaImage.setSize(390, 300);/繪畫大小 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類(演員)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(舞臺)一個Stage必須負(fù)責(zé)接收輸入事件,同時將它分配給演員。這通常是通過Stage的gdx.input.setinputprocessor來實(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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025授權(quán)購買企業(yè)債券合同范文
- 2024年中南財經(jīng)政法大學(xué)輔導(dǎo)員考試真題
- 2024年衢州龍游縣衛(wèi)健系統(tǒng)引進(jìn)事業(yè)單位衛(wèi)生人才真題
- MRC儲層改造技術(shù)研究與應(yīng)用-以西江24-3油田為例
- 2025年二手奢侈品鑒定標(biāo)準(zhǔn)與交易市場合規(guī)化策略研究報告
- 2025年二手交易電商信用評價體系創(chuàng)新與實(shí)踐案例報告
- 羅馬椅背部力量訓(xùn)練行業(yè)跨境出海項(xiàng)目商業(yè)計劃書
- 【保定】2025年河北碑店市公開招聘衛(wèi)健局下屬事業(yè)單位工作人員62人筆試歷年典型考題及考點(diǎn)剖析附帶答案詳解
- 安全員試題題庫及答案
- 兜底式增持-“餡餅”還是“陷阱”?-基于中順潔柔與寶通科技的案例分析
- JJG 475-2008電子式萬能試驗(yàn)機(jī)
- 配件供應(yīng)技術(shù)服務(wù)和質(zhì)保期服務(wù)計劃方案
- 《濟(jì)南市城鎮(zhèn)燃?xì)忸I(lǐng)域重大隱患判定指導(dǎo)手冊》
- 圖文高中英語語法if條件句If - Clauses
- 四川省安全員《A證》考試題庫及答案
- 職業(yè)生涯規(guī)劃書成長賽道
- 林木育種的種質(zhì)與材質(zhì)性狀評價
- 大模型在航空航天領(lǐng)域的應(yīng)用:智能探索宇宙的無限可能
- 《直流電源》課件
- 內(nèi)燃機(jī)車柴油機(jī) 課件 2-1-1 16V280型柴油機(jī) 固定件認(rèn)知
- FMECA方法及工程應(yīng)用案例
評論
0/150
提交評論