我想在我的LibGDX Android游戏中使用Google Play Game Services API的成就和排行榜。我所做的唯一一件事就是从游戏服务开发者网站上获取运行的示例。我已经尝试在我的项目中使用这段代码很多天了,但仍然一无所获。我也尝试过学习本教程http://helios.hud.ac.uk/u1070589/blog/?p=202但我没有“主游戏类(从ApplicationListener扩展而来的类)”,这是第7步所必需的。我只有
这是来自MainActivity的onCreate方法。JAVA
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
thingy=this;
RelativeLayout layout=new RelativeLayout(this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
View gameView=initializeForView(new DogeJump(this),false);
adView=new AdView(this,AdSize.IAB_MRECT,"ca-app-pub-XXXXXXX363095/9011689567");
adView.loadAd(new AdRequest());
layout.addView(gameView);
RelativeLayout.LayoutParams adParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layout.addView(adView,adParams);
setContentView(layout);
//initialize(new DogeJump(this),false);
}
对我来说,我有一个叫做LDGame的类,如下所示:
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
public class LDGame extends Game implements ApplicationListener {
private static RequestHandler requestHandler;
private static GoogleInterface platformInterface;
public LDGame(RequestHandler requestHandler, GoogleInterface anInterface) {
this.requestHandler = requestHandler;
this.platformInterface = anInterface;
}
@Override
public void create() {
Assets.loadAll();
//platformInterface.LogOut();
setScreen(new MainLogin(this, false));
}
@Override
public void resume() {
super.resume();
// Relase static resources
Assets.loadAll();
}
public GoogleInterface getPlatformInterface() {
return platformInterface;
}
public RequestHandler getRequestHandler(){
return requestHandler;
}
}
这就是我处理设置接口的基础知识的地方。(和你的狗一样)
然后我的主活动为Android端这样做
public class MainActivity extends AndroidApplication implements RequestHandler, GameHelperListener,
GoogleInterface, RealTimeMessageReceivedListener, RoomStatusUpdateListener, RoomUpdateListener,
OnInvitationReceivedListener, RealTimeReliableMessageSentListener, OnImageLoadedListener, OnStateLoadedListener, ConnectionCallbacks{
private View gameView;
private GameHelper mHelper;
private GameHelperInterface mGHInterface = null;
private LoginInterface mLoginInterface = null;
private ConfirmInterface mConfirmInterface = null;
private OnLeaderboardScoresLoadedListener theLeaderboardListener;
private RoomUpdateListener mRoomUpdateListener= this;
private Handler libGDXHandler;
// Debug tag
final static String TAG = "Liars Dice Multi";
// Request codes for the UIs that we show with startActivityForResult:
final static int RC_SELECT_PLAYERS = 10000;
final static int RC_INVITATION_INBOX = 10001;
final static int RC_WAITING_ROOM = 10002;
final static int RC_SETTINGS = 10004;
// Request Key for AppStateClient Slot
final static int ASC_SLOT_UNFINISHED_GAMES = 0;
static final int ASC_SLOT_SERVER_UNFINISHED_GAMES = 1;
// Room ID where the currently active game is taking place; null if we're
// not playing.
String mRoomId = null;
Room mRoomCurrent = null;
int mCurrentToken = 1;
// Are we playing in multiplayer mode?
boolean mMultiplayer = false;
// The participants in the currently active game
ArrayList<Participant> mParticipants = null;
ArrayList<String> listIgnoreTheseIDs = new ArrayList<String>();
// My participant ID in the currently active game
String mMyId = null;
//Token Trackers
ArrayList<Integer> readyToPlayTokens = new ArrayList<Integer>();
// If non-null, this is the id of the invitation we received via the
// invitation listener
String mIncomingInvitationId = null;
// Message buffer for sending messages
byte[] mMsgBuf = new byte[2];
ArrayList<String> messagesRecieved = new ArrayList<String>();
ArrayList<tokenInfo> listTokensSent = new ArrayList<MainActivity.tokenInfo>();
HashMap<Integer, tokenInfo> mapTokensSent = new HashMap<Integer, MainActivity.tokenInfo>();
// flag indicating whether we're dismissing the waiting room because the
// game is starting
boolean mWaitRoomDismissedFromCode = false;
Context activityContext;
MainActivity mA;
private AdHubView adView;
private boolean bCheckingTimes;
boolean bAnyRoomEvent = false;
private long oldCreationTime;
private Intent previousMatch;
private int iServerBadAttempts = -1;
public MainActivity(){
libGDXHandler = new Handler();
mHelper = new GameHelper(this);
mHelper.enableDebugLog(true, "Helper");
//create a listener for getting raw data back from leaderboard
theLeaderboardListener = new OnLeaderboardScoresLoadedListener() {
@Override
public void onLeaderboardScoresLoaded(int arg0, LeaderboardBuffer arg1,
LeaderboardScoreBuffer arg2) {
}
};
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SearchLayout layout = new SearchLayout(this);
SearchLayout.setSearchActivity(this);
// starts libGDX render thread
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
gameView = initializeForView(new LDGame(this, this), true);
adView = new AdHubView(this, "2011000001_001", AdSize.BANNER);
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layout.addView(gameView);
layout.addView(adView, adParams);
setContentView(layout);
//mHelper.setup(this);
mHelper.setup(this, GameHelper.CLIENT_GAMES | GameHelper.CLIENT_APPSTATE | GameHelper.CLIENT_PLUS, null);
mHelper.getPlusClient().registerConnectionCallbacks(this);
activityContext = this;
mA = this;
}
这是为了让我与游戏服务和谷歌云的东西接口...
对于我的屏幕(你可以从LDGame类中看到),我只是这样做
game.getPlatformInterface().anycallinYourInterface();
将我的电话发送到房子的libgdx端。。(不要忘记一个处理程序)
和任何屏幕是活动的,调用一个新的接口到libGDX端,这样:
//this will set the ConfirmInterface in the Android Activity
//and allow for future calls to call any implemented methods
//that are set inside the ConfirmInterface
private void setCallbackHandler(){
game.getRequestHandler().confirm(new ConfirmInterface() {
@Override
public void yes() {
Gdx.app.log("LDGame", "Clicked Yes");
dLog("have a direct invite, so waiting for it to process");
startNextScreen();
}
public void no() {
Gdx.app.log("LDGame", "Clicked No");
}
@Override
public void loginFailed(final boolean failedForPreviousNumberOfAttemtps, final long timeElapsed) {
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
setGoogleButtonImage(false);
if(failedForPreviousNumberOfAttemtps){
showFailedLoginForBadAttempts(timeElapsed);
}
}
});
}
@Override
public void loginSucceeded() {
//this means the login for both services is good, and the data returned meets
//whatever sign in criteria is set
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
setGoogleButtonImage(true);
game.getPlatformInterface().loadInvitations();
}
});
}
@Override
public void firstLogin() {
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
showFirstLogin();
}
});
}
@Override
public void googleSucceeded() {
//this means that google just returned a valid hit
game.getPlatformInterface().checkIfServerTimesAreValid();
showSignOutBar();
}
@Override
public void needToCheckTimesOnServer() {
//this means that there are three times or more on the server for incomplete games
//the only way to clear this is to try and do a quick check against a room login
Timer.schedule(new Timer.Task() {
@Override
public void run() {
game.getPlatformInterface().checkIfServerTimesAreValid();
}
}, 1f);
}
@Override
public void onInvitationReceived() {
game.getPlatformInterface().loadInvitations();
Assets.soundArrive.play();
}
@Override
public void haveInvitations(int count) {
// TODO Auto-generated method stub
}
});
}
因此,在我的Android系统中,我可以做到:
@Override
public void onSignInFailed() {
mConfirmInterface.loginFailed(false, 0);
}
}
在我的脑海中,Game类应该实现Application ationListener
,所以你缺少的遵循教程的类应该是DogeJump
。
抱歉我的问题,我被卡住了。我是lib gdx开发游戏的新手,不要严格评判我。我有我的游戏活动: } 我有两个屏幕: 还有我有暂停按钮的游戏屏幕: 还有我的主要问题--
我用Unity3d制作了一个游戏。我想在游戏中制作一个按钮,玩家可以点击这个按钮链接GooglePlay,给我的游戏打分。我需要什么插件,如何做到这一点?我刚找到这个:链接
我在play store上发布并运行了一款libGDX游戏,但我在游戏中实现排行榜时遇到了问题。我已经尝试了互联网上所有可用的方法,例如: LibGDX中的Google Play游戏服务 谷歌玩游戏服务教程示例 如何使用android studio在libgdx中设置google play游戏服务 我可能已经浏览了Google的所有资料,设置了排行榜、应用程序id和成就id,并通过Google p
问题内容: 我正在使用LibGDX开发Android游戏。菜单屏幕上有4个按钮,但是这些按钮中的按钮不起作用。 如何激活LibGDX中的按钮? 问题答案: 您必须将按钮添加到舞台并调用
我正在尝试用libgdx开发一个简单的蛇游戏。我的问题是,每次我想要繁殖一些苹果(纹理,20px宽X 20px高),它总是与蛇的身体重叠。我试图避免这种情况,但它在比赛中不断发生。 snake由多个部分组成-每个部分都是一个20px宽X 20px高的纹理(屏幕宽度是480px宽X 800px高) 以下是我迄今为止所做的尝试: 代码很容易解释。每时每刻,屏幕上都有3个不同的苹果。这段代码试图抽奖x-
我主要使用LibGDX为Android开发游戏。在桌面上进行测试是有帮助的。当我这样做时,我只是在Android Studio中设置“Desktop”项目来使用来自“Android”项目的资产,如这里所述。为了测试目的,这在我的本地机器上工作得很好。然而,如果我想打包我的游戏并发布给其他人在他们自己的机器上玩,这是行不通的。我如何包装我的游戏,以包括图形和音频资产?