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

时间:2014-04-16 20:55:29

标签: android animation screen andengine splash

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

我希望精灵在我们可以看到启动画面的整个时间内进行动画制作,同时加载在后台进行......这有意义吗?

以下是我的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 :(得分:0)

在onCreateResources()

中加载所有游戏资源
this.runOnUpdateThread(new Runnable() {
            @Override
            public void run() {
                sceneMan.loadFirstTimeRunAllResources();    
            }
        });