2

我目前正在研究 cocos2d-android 项目,其中精灵之间的交互是使用“场景”完成的,没有使用 xml 文件,所以现在要做一些其他任务,我在按钮的 onTouch 上使用 xml 布局文件。下面是替换按钮 onTouch 上的场景的代码,因为没有使用场景,我应该在这里使用什么逻辑?我搜索了很多,找不到解决方案。请帮我。

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);
        }
    };
4

2 回答 2

0

我认为你走错了方向,因为我和你之前的意图相同,但经过一系列研究,我发现:Android的cocos2d-x API只是一个在android设备上正常工作的包装器。主要的开发语言仍然是 C++ 的可移植性,这是一个太空游戏示例支持我的观点

于 2013-07-12T14:32:42.397 回答
0

要切换到 Android 中的另一个活动,您需要使用 JNI 代码将 cocos2d-x (c++) 的调用发送到当前的 android 活动。然后在那里开始一个新的活动。当您切换到另一个活动时,cocos2d-x 游戏将暂停。

于 2013-07-16T11:46:36.870 回答