我正在尝试游戏MrSnakey。当我运行它时,它不会给我任何错误。但是,模拟器在启动时会显示黑屏。你们是不是如何解决它? 关于我的项目需要解决这个问题的更多信息,请告诉我我会在这里发布。
首先是清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zardtechnologies.androidgames.mrsnakey"
android:versionCode="1"
android:versionName="1.0" >
<application
androidicon="@drawable/icon"
android:debuggable="true"
android:label="Mr. Snakey" >
<activity
android:name=".MrSnakeyActivity"
android:configChanges="keyboard|keyboardHidden|orientation"
android:label="Mr. Snakey"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="12" />
</manifest>
其次是MrSnakeyActivity
package com.zardtechnologies.androidgames.mrsnakey;
import com.zardtechnologies.framework.Screen;
import com.zardtechnologies.framework.impl.AndroidGame;
public class MrSnakeyActivity extends AndroidGame {
public Screen getStartScreen() {
return new LoadingScreen(this);
}
}
第三个从MrSnakeyActivity链接的AndroidGame活动
package com.zardtechnologies.androidgames.mrsnakey;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.view.Window;
import android.view.WindowManager;
import com.zardtechnologies.framework.Audio;
import com.zardtechnologies.framework.FileIO;
import com.zardtechnologies.framework.Game;
import com.zardtechnologies.framework.Graphics;
import com.zardtechnologies.framework.Input;
import com.zardtechnologies.framework.Screen;
public abstract class AndroidGame extends Activity implements Game {
AndroidFastRenderView renderView;
Graphics graphics;
Audio audio;
Input input;
FileIO fileIO;
Screen screen;
WakeLock wakeLock;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
int frameBufferWidth = isLandscape ? 480 : 320;
int frameBufferHeight = isLandscape ? 320 : 480;
Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth,
frameBufferHeight, Config.RGB_565);
float scaleX = (float) frameBufferWidth
/ getWindowManager().getDefaultDisplay().getWidth();
float scaleY = (float) frameBufferHeight
/ getWindowManager().getDefaultDisplay().getHeight();
renderView = new AndroidFastRenderView(this, frameBuffer);
graphics = new AndroidGraphics(getAssets(), frameBuffer);
fileIO = new AndroidFileIO(getAssets());
audio = new AndroidAudio(this);
input = new AndroidInput(this, renderView, scaleX, scaleY);
screen = getStartScreen();
setContentView(renderView);
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "GLGame");
}
@Override
public void onResume() {
super.onResume();
wakeLock.acquire();
screen.resume();
renderView.resume();
}
@Override
public void onPause() {
super.onPause();
wakeLock.release();
renderView.pause();
screen.pause();
if (isFinishing())
screen.dispose();
}
public Input getInput() {
return input;
}
public FileIO getFileIO() {
return fileIO;
}
public Graphics getGraphics() {
return graphics;
}
public Audio getAudio() {
return audio;
}
public void setScreen(Screen screen) {
if (screen == null)
throw new IllegalArgumentException("Screen must not be null");
this.screen.pause();
this.screen.dispose();
screen.resume();
screen.update(0);
this.screen = screen;
}
public Screen getCurrentScreen() {
return screen;
}
}
我不知道还需要哪些信息,因为我不知道是什么原因导致我的应用程序显示为黑屏。 噢,控制台日志:
[2012-04-29 14:24:54 - MrSnakey] Android Launch!
[2012-04-29 14:24:54 - MrSnakey] adb is running normally.
[2012-04-29 14:24:54 - MrSnakey] Performing com.zardtechnologies.androidgames.mrsnakey.MrSnakeyActivity activity launch
[2012-04-29 14:24:54 - MrSnakey] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'Test.Phone'
[2012-04-29 14:24:54 - MrSnakey] Uploading MrSnakey.apk onto device 'emulator-5554'
[2012-04-29 14:24:55 - MrSnakey] Installing MrSnakey.apk...
[2012-04-29 14:25:20 - MrSnakey] Success!
[2012-04-29 14:25:20 - MrSnakey] Project dependency found, installing: AndroidGamesFramework
[2012-04-29 14:25:22 - AndroidGamesFramework] Application already deployed. No need to reinstall.
[2012-04-29 14:25:22 - MrSnakey] Project dependency found, installing: AndroidGamesFrameworkImplementation
[2012-04-29 14:25:24 - AndroidGamesFrameworkImplementation] Application already deployed. No need to reinstall.
[2012-04-29 14:25:24 - AndroidGamesFrameworkImplementation] Project dependency found, installing: AndroidGamesFramework
[2012-04-29 14:25:26 - AndroidGamesFramework] Application already deployed. No need to reinstall.
[2012-04-29 14:25:26 - MrSnakey] Starting activity com.zardtechnologies.androidgames.mrsnakey.MrSnakeyActivity on device emulator-5554
[2012-04-29 14:25:28 - MrSnakey] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.zardtechnologies.androidgames.mrsnakey/.MrSnakeyActivity }
没有错误。我认为该应用程序运行得非常好,只是它不会让我进入游戏。请帮我解决黑屏问题。如果你们需要了解更多信息,请告诉我,我会在这里发布。谢谢
答案 0 :(得分:1)
您没有在任何地方加载布局文件。你需要打个电话
setContentView(R.layout.main)
中的AndroidGame
。假设您的布局文件名为main.xml