首页 文章

当onTimePassed点击加载游戏资源时,Andengine AnimatedSprite停止动画(启动/加载场景)

提问于
浏览
1

所以我正在创建一个启动画面,在后台加载游戏资源 . 在启动画面期间,它们是一个动画精灵,它应该位于屏幕的中心并设置动画,直到资源全部加载完毕,我只需将场景切换到菜单场景即可 . 然而,此时精灵会动画很短的时间,然后冻结并且几秒钟内无所事事,然后加载菜单场景(这个“几秒钟”更改持续时间取决于手机运行的速度有多快在,例如我的手机(新手)就像一瞬间,但是我的朋友电话(旧的)需要4或5秒) .

I want to have the sprite animate for the entire time that we can see the splash screen, whilst the loading is happening in the background... Does that make sense?

下面是我的MainActivity类......

public class MainActivity extends BaseGameActivity 
{
protected static int CAMERA_WIDTH = 480;
protected static  int CAMERA_HEIGHT = 800;

protected PhysicsWorld mPhysicsWorld;
SceneManager sceneMan;
Camera camera;

@SuppressWarnings("deprecation")
@Override
public EngineOptions onCreateEngineOptions() 
{
    camera = new Camera(0, 0, CAMERA_WIDTH,CAMERA_HEIGHT);
    float camwid = CAMERA_WIDTH;
    float camhi = CAMERA_HEIGHT;

    CropResolutionPolicy pop = new CropResolutionPolicy(camwid,camhi);

    return new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, pop, camera);
}

@Override
public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws Exception 
{
    sceneMan = new SceneManager(this, mEngine, camera);
    sceneMan.loadSplashResources();
    pOnCreateResourcesCallback.onCreateResourcesFinished();
}

@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws Exception 
{
    pOnCreateSceneCallback.onCreateSceneFinished(sceneMan.createSplashScene());
}

@Override
public void onPopulateScene(Scene pScene,OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception 
{
    mEngine.registerUpdateHandler(new TimerHandler(2f, new ITimerCallback() 
    {
        @Override
        public void onTimePassed(TimerHandler pTimerHandler) 
        {
            mEngine.unregisterUpdateHandler(pTimerHandler);
            sceneMan.loadFirstTimeRunAllResources();
            sceneMan.createMenuScene();         
            sceneMan.setCurrentScene(AllScenes.MENU_SCREEN);
        }
    }));

    pOnPopulateSceneCallback.onPopulateSceneFinished();
}
}

下面是创建启动场景代码,它为我的启动场景创建东西并告诉精灵动画,这位于另一个处理场景加载和创建的类中......

public Scene createSplashScene()
{
    //Will only call once!
    //Will never return to this scene
    splashScene = new Scene();
    splashScene.setBackground(new Background(0,0,0));
    AnimatedSprite icon = new AnimatedSprite(0, 0, splashAniTR, engine.getVertexBufferObjectManager());
    icon.setPosition(camera.getWidth()-(camera.getWidth()/2)-(icon.getWidth()/2)+12,camera.getHeight()-(camera.getHeight()/2)-icon.getHeight()/2);
    icon.animate(300);
    splashScene.attachChild(icon);
    return splashScene;

}

1 回答

  • 0

    在onCreateResources()中加载所有游戏资源

    this.runOnUpdateThread(new Runnable() {
                @Override
                public void run() {
                    sceneMan.loadFirstTimeRunAllResources();    
                }
            });
    

相关问题