2013-07-12 28 views
2

我目前正在使用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); 
     } 
    }; 
+0

當你試圖運行這個演示,發生了什麼。 –

+0

我在這一行scene.addChild(new GameLayer(),-1)上得到了錯誤;這是由於類「@AM –

+0

」中的「擴展CCLayer」的缺失。我也試圖從Scene調用到Activity,但是它不會允許做這件事..只有我們可以在CCLayer上工作..如果我能解決這個問題。我會通知你這件事 –

回答

0

我想你已經去了錯誤的方向,因爲我之前有相同意向的你,但經過一系列的研究,我發現:Android的cocos2d-x API只是在Android設備上正常工作的一個包裝。主要的開發語言仍然是可移植的C++,Here is a Space Game example support my point

0

要切換到Android中的其他活動,您需要使用JNI代碼將來自cocos2d-x(C++)的調用發送到當前的android活動。然後在那裏開始新的活動。切換到其他活動時,cocos2d-x遊戲將暫停。

相關問題