Java 如何从libgdx中的另一个类调用方法

Java 如何从libgdx中的另一个类调用方法,java,class,methods,libgdx,Java,Class,Methods,Libgdx,我想从classMyGdxGame中的render()调用方法walo(): public class MyGdxGame extends ApplicationAdapter{ public void render() { walo(); } } public class AndroidLauncher extends AndroidApplication { AndroidLauncher android =new AndroidLauncher(

我想从classMyGdxGame中的render()调用方法walo():

public class MyGdxGame extends ApplicationAdapter{
    public void render() {
        walo();
    }
} 

public class AndroidLauncher extends AndroidApplication {
    AndroidLauncher android =new AndroidLauncher();

    public void walo() {
        Toast.makeText(getApplicationContext(), "You Don't Have Enough Money",
          Toast.LENGTH_LONG).show();
    }
}

在core中创建接口,在AndroidLauncher中实现该接口并将其发送到游戏。 所以您可以调用方法或传递数据进行渲染

接口:

    public interface SomeInterface    {
    public void walo();
}
安德鲁伊德拉舍尔:

   public class AndroidLauncher implements SomeInterface{

        @Override
        protected void onCreate() {    

        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        initialize(new MyGdxGame(this), config);

    }

        public void walo() {
          Toast.makeText(getApplicationContext(), "You Don't Have Enough Money",
          Toast.LENGTH_LONG).show();
    }
    }
游戏课

  public MyGdxgame(SomeInterface myinterface)           {
            this.myinterface=myinterface;
        }
   public render()            {
            myinterface.walo()
        }
下面是一个示例(我的google play服务界面)和一个指向我的libgdx游戏开源数据的链接

    public interface PlayServices
{
    public void signIn();
    public void signOut();
    public void rateGame();
    public void unlockAchievement(String str);
    public void submitScore(int highScore);
    public void submitLevel(int highLevel);
    public void showAchievement();
    public void showScore();
    public void showLevel();
    public boolean isSignedIn();
    public void showBannerAd();
    public void hideBannerAd();
    public void showInterstitialAd (Runnable then);
    public void showRewardedVideo();
    public boolean isRewardEarned();
}
你可以看到这样的广告和视频奖励


您可能还想查看有关此问题的wiki: