1

我在方法中放了一个 log.d,它从不报告。游戏的 run() 方法已执行,但我防御性地等待 surfaceCreated 方法返回,然后再继续。

注意:游戏是线程,TouchPanel 扩展 SurfaceView 实现 SurfaceHolder.Callback

private final void runGame() {
        savedPos = 0;
        resumeGame();
        touchPanel = (TouchPanel)findViewById(com.mysite.mygame.R.id.touchPanel);
        touchPanel.setMinimumHeight(displayWidth);
        touchPanel.setParams(this, writeLock, gemSize9, gemSize12, marg);
        textUpdate = new TextUpdate(this, d);
        gm = new Game(tok9, tok12, m, d, this, textHandler, textUpdate, touchPanel, marg, gemSize9, gemSize12, readLock, writeLock);
        initBitmaps();
        gm.start();
}
private final void resumeGame() {
        loadBGMusic();
        layout = Layout.GAME;
        setContentView(com.mysite.mygame.R.layout.game);
        writeLock.lock(); try { paused = false; } finally { writeLock.unlock(); }
}

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/rel"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:background="@drawable/backrepeat"
   android:keepScreenOn="true"
   >
    <com.mysite.mygame.TouchPanel
       android:id="@+id/touchPanel"
       android:layout_width="fill_parent"
       android:layout_height="0dp"
       android:clickable="true"
       android:focusableInTouchMode="true"
       />
</RelativeLayout>

public TouchPanel(Context context, AttributeSet attrs) {
        super(context, attrs);
        getHolder().addCallback(this);
}
4

1 回答 1

0

我想到了。

@id/touchPanel

应该有

android:layout_height != 0

android:layout_width != 0

在 SurfaceView 中创建 Surface。

于 2012-07-12T04:07:34.207 回答