我剛開始創建Android遊戲,並決定從Retro Chicken的教程開始。遊戲究竟在哪裏開始?
我只是沒有得到的是遊戲真正開始聽命令的地方? 通常他們有一個功能,如public void run()
被調用。 主要是這樣的:
game = new GamePanel(this);
setContentView(game);
,並呼籲主要的構造函數是:
public GamePanel(Context context){
super(context);
this.getHolder().addCallback(this);
thread = new MainThread(getHolder(), this); // Inherits [Thread] class. Code posted
player = new RectPlayer(new Rect(100,100,200,200), Color.rgb(255,0,0)); Class made by me. Has nothing special.
playerPoint = new Point(150,150);
// We ensure that THIS canvas will get the focus.
setFocusable(true);
}
我通過一些super
調用衝浪,但仍沒有
- MainThread.java
-
編輯:我感興趣什麼叫
run
函數,在哪裏以及如何?
所以,基本上,'surfaceCreated'是啓動所有的方法之一。謝謝,這就是我一直在尋找的! – SnuKies
'surfaceCreated'包含的代碼,啓動遊戲線程塊,但只叫,因爲你'的setContentView(遊戲);',如果你要創建的遊戲對象,但從來沒有把它添加到視圖,該線程將永遠不會開始。你不應該直接調用它,而是應該調用層次結構,否則最終會出現多個流氓線程。 –