我目前正在使用cocos2d-android項目,其中sprite之間的交互使用'場景'沒有使用xml文件,所以現在要做一些其他的任務,我在onTouch的按鈕上使用xml佈局文件。 下面是替換onTouch按鈕上的場景的代碼,因爲場景沒有被使用過,我應該在這裏使用什麼邏輯?我搜查了很多,找不到解決方案。請幫幫我。如何在cocos2d-android中使用活動?
public void callbackGameLayer(Object sender) {
//Global.playSoundEffect(R.raw.button);
CCScene scene = CCScene.node();
scene.addChild(new GameLayer(), -1);
CCDirector.sharedDirector().replaceScene(scene);
}
這是活性,其流量已去
public class IntermediateMain extends Activity {
protected CCGLSurfaceView mGlSurfaceView;
private static int MAX_GAME_TIME_SECONDS = 300;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
// get full screen setup and keep screen bright and on when the window
// is visible
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mGlSurfaceView = new CCGLSurfaceView(this);
setContentView(R.layout.main);
final Button newGame = (Button) findViewById(R.id.start_game_btn);
final TextView numSecondsTextView = (TextView) findViewById(R.id.num_seconds_text_view);
final TextView numSacksTextView = (TextView) findViewById(R.id.num_sacks_text_view);
OnSeekBarChangeListener changeListener = new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
int currentGameTimeInSeconds = (progress * MAX_GAME_TIME_SECONDS)/100;
numSecondsTextView.setText(Integer
.toString(currentGameTimeInSeconds));
numSacksTextView.setText(Integer.toString(IntermediateGameLayer
.numSacksInGame(currentGameTimeInSeconds)));
newGame.setEnabled(currentGameTimeInSeconds > 0);
}
};
當你試圖運行這個演示,發生了什麼。 –
我在這一行scene.addChild(new GameLayer(),-1)上得到了錯誤;這是由於類「@AM –
」中的「擴展CCLayer」的缺失。我也試圖從Scene調用到Activity,但是它不會允許做這件事..只有我們可以在CCLayer上工作..如果我能解決這個問題。我會通知你這件事 –