0
遊戲從MainActivity
類(擴展Activity
),然後開始呼籲新GamePanel
擴展SurfaceView
,並且有很多類,更新遊戲,所以還有一類( GameplayScene
),檢查觸摸並檢查遊戲發生了什麼(如果用戶輸贏),所以有更新方法檢查玩家是贏還是輸,如果玩家贏或輸,那麼我想開始一個新的有一個按鈕來重新啓動遊戲,應用程序沒有響應
問題是:在開始新的活動(通過使用Intent
從一個類沒有擴展任何東西)應用程序不響應(但它顯示第Ë新正確的活動)
,從開始的新活動()類:
public class GameplayScene implements Scene {
public GameplayScene() {
....
@Override
public void recieveTouch(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (!youWin && !gameOver && player.getRectangle().contains((int) event.getX(), (int) event.getY()))
movingPlayer = true;
forBegin = false;
if (gameOver && System.currentTimeMillis() - gameOverTime >= 2000) {
reset();
gameOver = false;
}
if (youWin && System.currentTimeMillis() - winTime >= 2000) {
reset();
youWin = false;
}
if(!youWin && !gameOver && !movingPlayer) {
if(!forBegin && System.currentTimeMillis() - fireTime >= 200) {
touchFire = true;
count = 1;
fireTime = System.currentTimeMillis();
}
}
break;
case MotionEvent.ACTION_MOVE:
if (!youWin && !gameOver && movingPlayer)
playerPoint.set((int) event.getX(), (int) event.getY());
break;
case MotionEvent.ACTION_UP:
movingPlayer = false;
touchFire = false;
break;
}
}
//@Override
public void draw(Canvas canvas) {
canvas.drawColor(Color.BLACK);
//Drawable d = getDrawable(getResources(), R.drawable.bgi);
//d.setBounds(0, 0,canvas.getWidth(), canvas.getHeight());
//d.draw(canvas);
//canvas.drawBitmap(bgi, null, new Rect(0, 0, canvas.getWidth(), canvas.getHeight()),new Paint());
player.draw(canvas);
obstacleManager.draw(canvas);
if(gameOver) {
Context contX = Constants.CONTEXT;
Intent intent = new Intent(contX , result.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("toWR",0);
contX.startActivity(intent);
}
if(youWin) {
Context contX = Constants.CONTEXT;
Intent intent = new Intent(contX , result.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("toWR",1);
contX.startActivity(intent);
}
}
}
Android清單:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".main_menu"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"
android:screenOrientation="portrait" />
<SurfaceView android:name=".GamePanel"
android:screenOrientation="portrait" />
<activity android:name=".result"
android:screenOrientation="portrait" />
</application>
在您的新Activity的'onCreate(...)'中放入日誌,並在按下按鈕時監視logcat。我懷疑你正在啓動太多的'結果'活動 – Jon