-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManagedScene.java
70 lines (61 loc) · 2.29 KB
/
ManagedScene.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package mkat.apps.spacewars;
import org.andengine.entity.scene.Scene;
import android.util.Log;
public abstract class ManagedScene extends Scene {
//Tells the Scene Manager that the managed scene either has or doesn't have a loading screen.
public final boolean hasLoadingScreen;
// The minimum length of time (in seconds) that the loading screen should be displayed.
public final float minLoadingScreenTime;
// Keeps track of how long the loading screen has been visible. Set by the SceneManager.
public float elapsedLoadingScreenTime = 0f;
//Is set TRUE if the scene is loaded.
public boolean isLoaded = false;
//Convenience constructor that disables the loading screen.
public ManagedScene() {
this(0f);
}
//Convenience constructor that sets the minimum length of the loading screen and sets hasLoadingScreen accordingly.
public ManagedScene(final float pLoadingScreenMinimumSecondsShown) {
minLoadingScreenTime = pLoadingScreenMinimumSecondsShown;
hasLoadingScreen = (minLoadingScreenTime > 0f);
}
//Called by the Scene Manager. It calls onLoadScene if loading is needed, sets the isLoaded status, and pauses the scene while it's not shown.
public void onLoadManagedScene() {
if (!isLoaded) {
Log.v("","Loading Scene");
onLoadScene();
isLoaded = true;
this.setIgnoreUpdate(true);
}
}
//Called by the Scene Manager. It calls onUnloadScene if the scene has been previously loaded and sets the isLoaded status.
public void onUnloadManagedScene() {
if (isLoaded){
isLoaded = false;
onUnloadScene();
}
}
// Called by the Scene Manager. It unpauses the scene before showing it.
public void onShowManagedScene() {
this.setIgnoreUpdate(false);
onShowScene();
Log.v("","Showing Scene");
}
//Called by the Scene Manager. It pauses the scene before hiding it.
public void onHideManagedScene() {
this.setIgnoreUpdate(true);
ResourceManager.getInstance().engine.runOnUpdateThread(new Runnable() {
@Override
public void run() {
onHideScene();
}
});
}
//Methods to Override in the subclasses.
public abstract Scene onLoadingScreenLoadandShown();
public abstract void onLoadingScreenUnloadAndHidden();
public abstract void onLoadScene();
public abstract void onShowScene();
public abstract void onHideScene();
public abstract void onUnloadScene();
}