显示不同的场景,不同的层次。 AndEngine [英] Show different scenes for different levels. AndEngine

查看:108
本文介绍了显示不同的场景,不同的层次。 AndEngine的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AndEngine的游戏2D。想加载不同的活动或更好不同的场景的不同级别和用于主菜单。如何实现这一目标? ..Where我可以找到一个例子?

I'm using AndEngine for a Game 2d. Wanna to load different Activities or better different Scenes for the different levels and for the main menu. How to achieve this ? ..Where can I find an example ?

推荐答案

我会建议你使用的场景,而不是活动,以避免交换活动之间黑屏。创建你自己的场景管理器,并用它来改变屏幕。 基本例如:

I would recommend for you to use scenes instead activities to avoid black screens between switching activities. Create your own scene manager and use it for changing screens. Basic example:

public class SceneManager {
    private static Game game; // your main activity
    private static SceneManager sm;

    private Scene mScene;

    private SceneManager(){
    }

    public static void init(Game pGame){
            SceneManager.game = pGame;
    }

    public static SceneManager getManager(){
            if(game == null) throw new IllegalStateException("You must first initialize scenemanager class");
            if(sm == null) return sm = new SceneManager();

            return sm;
    }

    public void setMainMenuScreen(){
            mScene = new MainMenuScene();
            game.getEngine().setScene(mScene);
    }

    public void setGameScreen(){
            mScene = new GameScene();
            game.getEngine().setScene(mScene);
    }

    public Scene getCurrScene(){
            return mScene;
    }
}

而在你的主类Game.java首先你应该初始化场景管理器类,并得到本地实例。在此之后随时根据您的游戏逻辑使用它:

And in your main class Game.java firstly you should initialize your scene manager class and get local instance. After this feel free to use it according your game logic:

private SceneManager sm;
SceneManager.init(this);
sm = SceneManager.getManager();
sm.setMainMenuScreen();

...

sm.setGameScreen(); 

这篇关于显示不同的场景,不同的层次。 AndEngine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆