[英]Attempting to Implement a Thread for a Game Loop
我是一個學習Android開發的新手,下一步我必須采取的步驟是能夠理解線程以實現游戲循環。
我從Google和StackOverflow那里獲取了知識,並從示例中獲取了一些片段,以得出似乎無法正常工作的大量代碼:
MainActivity.java是帶有播放按鈕的簡單標題屏幕。 這似乎工作正常,並將鏈接到下一個活動。 但是,每當嘗試加載下一個活動時,我都會崩潰。 我對錯誤的評價使我相信線程存在RelativeActivity問題,但是我不確定問題到底是什么,我很困惑。
這是我拋出的錯誤,我在嘗試破譯該問題時遇到問題。
謝謝。
R.id.layout
是一個RelativeLayout
,但你正在試圖將其轉換為GameView
,這是造成你的崩潰。
編輯:
要將您的GameView
添加到RelativeLayout
您可以執行
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.your.package.GameView
android:id="@+id/my_game_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ship1" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ship1" />
</RelativeLayout>
並用
GameView myGameView = (GameView) findViewById(R.id.my_game_view);
嗯,從您到目前為止編寫的代碼中,我可以解釋ClassCastException的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.