我猜你正试图从 Android 模块向你的核心模块发送一个 PlayServices 的实例。如果不是这种情况,请更正我并提供更多代码,因为我无法根据您提供的信息做出任何其他事情。
您需要使用接口。
在您的核心模块中创建一个接口。其中有connectToGooglePlayServices()、unlockAchivement()等必要的功能。所有的东西都是Android独有的。
public class AndroidLauncher extends AndroidApplication implements ThatInterfaceClass {
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new MyGdxGame(this), config);
}
@Override
public void connectToGooglePlayServices() {
//connect to play services here
}
@Override
public void unlockAchivement() {
// unlock achivement etc.
}
}
这里的重要部分是将其作为参数提供给MyGdxGame 类构造函数,并实现ThatInterfaceClass。
之后在你的 MyGdxGame 类的构造函数中添加一个参数。
public class MyGdxGame extends ApplicationAdapter {
public void MyGdxGame (ThatInterfaceClass interface) {
this.interface = interface;
}
// create etc... Other functions....
}
现在要连接到 google play 服务或解锁成就,只需拨打interface.connectToGooglePlayServices()
这里有一个链接可以更好地解释这一点。
https://github.com/libgdx/libgdx/wiki/Interfacing-with-platform-specific-code
编辑: 问题似乎出在您未在此处提供的代码中。看看这个你应该如何创建的例子
e MainMenu 类的一个实例。
MainGame mainGame = new MainGame(playServices);
MainMenu mainMenu = new MainMenu(mainGame);
我相信你正在构建这样的 MainMenu 类:
MainMenu mainMenu = new MainMenu();
只要你有这个构造函数:
public MainGame(PlayServices playServices)
{
this.playServices = playServices;
}
你不能使用没有 PlayServices 参数的构造函数。但是您可以删除您的构造函数或删除 PlayServices 参数并像这样使用它:
MainMenu mainMenu = new MainMenu();
mainMenu.setPlayServices(playServices);
这是另一个和你一样的问题:
"Actual or formal argument lists differs in length"
编辑 2: 您的 MainMenu 类是否在 核心模块 的 android 模块 中?如果它不在 android 模块 中,则不能使用 PlayServices 类(也不能有实例)。也不要寻找解决方法,只需使用接口来启动连接。正如我在最初的回答中所说的那样。
编辑 3:最终版:如果您之前已经介绍过本教程,对我们双方来说可能会更容易。
您在 cmets 中发送的图像说 playServices 无法解析:
确保您没有输入任何错误。
确保 PlayServices 接口在核心模块中。
再次阅读教程。确保您正确添加了库、依赖项等。
本教程告诉您创建 AndroidLauncher 活动。但是 libGdx 默认会创建它。
除此之外,如果不坐在你的椅子上,我无法进一步帮助你。对于您的下一个问题,请提供更多信息。还有很多。