2016-12-02 40 views
0

好的,我只是想出來。我對Android編碼非常陌生。我也只用AIDE在手機上完成。如何在gdx遊戲中打開另一個課程

我想開標記aboutgame.java

我不知道如何發佈我的代碼另一個類,但在這裏不用。

package com.bernco.screenoff; 

import com.badlogic.gdx.*; 
import com.badlogic.gdx.graphics.*; 
import com.badlogic.gdx.graphics.g2d.*; 
import com.badlogic.gdx.scenes.scene2d.*; 
import com.badlogic.gdx.scenes.scene2d.ui.*; 
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; 
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle; 
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton; 




public class MyGdxGame implements ApplicationListener 
{ 

    Texture texture; 
    Texture pwrdby; 
    Texture about; 
    SpriteBatch batch; 
    SpriteBatch pwrbtch; 
    SpriteBatch abtbtch; 







    @Override 
    public void create() 
    { 
     texture = new Texture(Gdx.files.internal("dark-android.jpg")); 
     about = new Texture(Gdx.files.internal("about.png")); 
     pwrdby = new Texture(Gdx.files.internal("powered-by.png")); 
     batch = new SpriteBatch(); 
     abtbtch = new SpriteBatch(); 
     pwrbtch = new SpriteBatch(); 
    } 

    @Override 
    public void render() 
    {   
     Gdx.gl.glClearColor(0f, 0f, 0f, 0f); 
     Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
     abtbtch.begin(); 
     abtbtch.draw(about, Gdx.graphics.getWidth() - about.getWidth()/2, Gdx.graphics.getHeight() - about.getHeight()/2, 
       Gdx.graphics.getWidth()/8, Gdx.graphics.getWidth()/8); 

     abtbtch.end(); 

     batch.begin(); 
     batch.draw(texture, Gdx.graphics.getWidth()/80, 0, 
        Gdx.graphics.getWidth()/1, Gdx.graphics.getWidth()/2); 
     batch.end(); 

     pwrbtch.begin(); 
     pwrbtch.draw(pwrdby, Gdx.graphics.getWidth()/80, 0, 
        Gdx.graphics.getWidth()/4, Gdx.graphics.getWidth()/3); 
     pwrbtch.end(); 
    } 

    @Override 
    public void dispose() 
    { 
    } 

    @Override 
    public void resize(int width, int height) 
    { 
    } 

    @Override 
    public void pause() 
    { 
    } 

    @Override 
    public void resume() 
    { 
    } 


} 
+0

建議:投資一個好的LibGDX_book_並按照例子逐步進行。我個人非常喜歡「與LibGDX開始遊戲開發」。 – DavidS

回答

3

歡迎來到StackOverflow!

在高層次上,多屏幕遊戲需要一個類來代表您的應用程序,以及一些其他類來表示遊戲中的不同屏幕。

在libGDX中,這意味着代替MyGdxGame類實現ApplicationListener,您希望它可以擴展Game類。這是libGDX提供的一個實用程序類,它爲您提供了一些管理屏幕所需的框架代碼。這個類不是繪製自己,而是告訴你的一個屏幕類來繪製自己。然後,當您想要更換屏幕時,請撥打Game#setScreen(...)將其指向新屏幕。

然後,您的每個屏幕類將需要實現Screen界面,該界面將向您展示您需要實施的方法以便與您的遊戲一起使用。

我建議你看看官方libGDX wiki上的兩個教程:A Simple GameExtending the Simple Game。他們給出了Desktop和Android的示例,後者將向您介紹如何使用GameScreen的示例。

+0

所以你在說什麼,而不是說「實現ApplicationListener」它應該說「像擴展MyGdxGame」?對不起,我只是在學習。教訓和例子很少。我只能猜測你說的很多東西(至少在如何將它應用到我自己的應用程序中)。我只在這裏呆了2周。但非常感謝您的幫助 –

+0

關閉它應該是'MyGdxGame擴展遊戲'。在這裏給我多一點背景知識,你對Android或Java有很多經驗嗎? – John