我想用 AsyncTask 初始化游戏引擎的所有组件。有人可以指导我如何做到这一点吗?
我想要这样的东西: 1. 在代码运行之前,设置一个启动画面(.xml) 2. 运行初始化代码 3. 完成后,运行游戏的加载屏幕
这是我当前的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Display splash screen
if(this.splashScreen != null) {
// .xml
setContentView(this.splashScreen);
}
// Do all the initialization
// Acquire a wakeLock to prevent the phone from sleeping
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "GLGame");
// Setup all the Game Engine components
gameEngineLog = new WSLog("WSGameEngine");
gameEngineLog.setLogType(this.gameEngineLogType);
gameLog = new WSLog(this.gameLogTAG);
gameLog.setLogType(this.gameLogType);
io = new FileIO(this, getAssets());
audio = new Audio(this);
wsScreen = new WSScreen(this, this.screenResizeType, this.customTopYGap, this.customLeftXGap, this.gameScreenWidth, this.gameScreenHeight);
graphics = new Graphics(this, wsScreen.getGameScreen(), wsScreen.getGameScreenextended());
renderView = new RenderView(this, wsScreen.getGameScreen(), wsScreen.getGameScreenextended(), FPS, maxFrameskippes);
input = new Input(this, renderView, logGameEngineInputLog);
networkSocket = new NetworkSocket(this);
this.gameEngineLog.d(classTAG, "Completed initialization");
setContentView(renderView);
// Check that the developer has initialized the assets
if(this.assets == null) {
this.gameEngineLog.w(classTAG, "The assets for the game haven't been defined!");
}
this.getNetworkSocket().useAnalytics(this.analyticsAppAPIKey);
this.getNetworkSocket().useServerCommunication(this.serverCommunicationAppID, this.serverCommunicationClientKey);
this.getNetworkSocket().useFacebookCommunicaiton(this.facebookCommunicationAppID);
// Check if server communication should be initialized
if(this.networkSocket.getUseOfServerCommunication() == true) {
this.networkSocket.getServerCommunication().initialize(this, this.networkSocket.getServerCommunicationAppID(), this.networkSocket.getServerCommunicationClientKey());
}
// Check if facebook communication should be initialized
if(this.networkSocket.getUseFacebookCommunication() == true) {
this.networkSocket.getFacebookCommunication().initialize(this.networkSocket.getFacebookCommunicationAppID(), true);
}
// Start the Load screen
// Once all of this code has been executed, the class that extends this class calls "setScreen(new LoadScreen(this));" to set the LoadScreen, which
// loads all the assets of the game
}