1. Loading scene:
It will be a simple white scene, with only one object - text saying "loading..." - we will display this scene while pre-loading the game scene and its resources. Please refer to the class diagram from article number 2 (while displaying loading scene, menu textures will be unloaded, game resources will be loaded, and game scene will be initialized) This scene will be also used to get back to the menu scene from the game scene (vice versa, unloading game scene and its textures and loading menu textures) By using this simple approach, we will minimize memory usage.
lets first create a loading scene class, lets call it LoadingScene. As previously, use our BaseScene class as an extension and add unimplemented methods. Lets also create a white background for our scene.
package com.mindew.fruitecollector;
import org.andengine.entity.scene.background.Background;
import org.andengine.util.adt.color.Color;
import com.mindew.fruitecollector.BaseScene;
import com.mindew.fruitecollector.SceneManager.SceneType;
public class LoadingScene extends BaseScene
{
@Override
public void createScene()
{
setBackground(new Background(Color.WHITE));
}
@Override
public void onBackKeyPressed()
{
return;
}
@Override
public SceneType getSceneType()
{
return SceneType.SCENE_LOADING;
}
@Override
public void disposeScene()
{
}
}
As you probably noticed, inside onBackKeyPressed() we just return, which means we do not perform any actions (because we do not want to do anything while the loading scene is being displayed and the player touches the phone`s back button)
3. Creating "loading..." text:
As I stated at the beginning, we will need text saying "loading..." to do this, we will first have to load some font to create the text. Its up to you what kind of font you will use.
Open our ResourcesManager class, lets create a new method responsible for loading our Font, we also create our Font in a public field.
public Font font;
private void loadMenuFonts()
{
FontFactory.setAssetBasePath("font/");
final ITexture mainFontTexture = new BitmapTextureAtlas(activity.getTextureManager(), 256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
font = FontFactory.createStrokeFromAsset(activity.getFontManager(), mainFontTexture, activity.getAssets(), "font.ttf", 50, true, Color.WHITE, 2, Color.BLACK);
font.load();
}
I am loading a font called font.ttf from the assets/font/ folder.
Now lets execute our method responsible for loading fonts inside the loadMenuResources() method, so it should now look like this:
public void loadMenuResources()
{
loadMenuGraphics();
loadMenuAudio();
loadMenuFonts();
}
The code responsible for loading font is ready, lets go back to our loading scene class, and create a Text object and place it in the middle of the screen.
@Override
public void createScene()
{
setBackground(new Background(Color.WHITE));
attachChild(new Text(400, 240, resourcesManager.font, "Loading...", vbom));
}
Initialize the loading scene inside our SceneManager, inside createMenuScene()
public void createMenuScene()
{
ResourcesManager.getInstance().loadMenuResources();
menuScene = new MainMenuScene();
loadingScene = new LoadingScene();
SceneManager.getInstance().setScene(menuScene);
disposeSplashScene();
}
That's all for now, we will not use it yet as we will have to create a game scene first, and later code responsible for displaying the loading scene when necessary (see the code diagram to understand when the loading scene will be displayed)
It will be a simple white scene, with only one object - text saying "loading..." - we will display this scene while pre-loading the game scene and its resources. Please refer to the class diagram from article number 2 (while displaying loading scene, menu textures will be unloaded, game resources will be loaded, and game scene will be initialized) This scene will be also used to get back to the menu scene from the game scene (vice versa, unloading game scene and its textures and loading menu textures) By using this simple approach, we will minimize memory usage.
lets first create a loading scene class, lets call it LoadingScene. As previously, use our BaseScene class as an extension and add unimplemented methods. Lets also create a white background for our scene.
package com.mindew.fruitecollector;
import org.andengine.util.adt.color.Color;
import com.mindew.fruitecollector.BaseScene;
import com.mindew.fruitecollector.SceneManager.SceneType;
public class LoadingScene extends BaseScene
{
@Override
public void createScene()
{
setBackground(new Background(Color.WHITE));
}
@Override
public void onBackKeyPressed()
{
return;
}
@Override
public SceneType getSceneType()
{
return SceneType.SCENE_LOADING;
}
@Override
public void disposeScene()
{
}
}
As you probably noticed, inside onBackKeyPressed() we just return, which means we do not perform any actions (because we do not want to do anything while the loading scene is being displayed and the player touches the phone`s back button)
3. Creating "loading..." text:
As I stated at the beginning, we will need text saying "loading..." to do this, we will first have to load some font to create the text. Its up to you what kind of font you will use.
Open our ResourcesManager class, lets create a new method responsible for loading our Font, we also create our Font in a public field.
public Font font;
private void loadMenuFonts()
{
FontFactory.setAssetBasePath("font/");
final ITexture mainFontTexture = new BitmapTextureAtlas(activity.getTextureManager(), 256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
font = FontFactory.createStrokeFromAsset(activity.getFontManager(), mainFontTexture, activity.getAssets(), "font.ttf", 50, true, Color.WHITE, 2, Color.BLACK);
font.load();
}
I am loading a font called font.ttf from the assets/font/ folder.
Now lets execute our method responsible for loading fonts inside the loadMenuResources() method, so it should now look like this:
public void loadMenuResources()
{
loadMenuGraphics();
loadMenuAudio();
loadMenuFonts();
}
The code responsible for loading font is ready, lets go back to our loading scene class, and create a Text object and place it in the middle of the screen.
@Override
public void createScene()
{
setBackground(new Background(Color.WHITE));
attachChild(new Text(400, 240, resourcesManager.font, "Loading...", vbom));
}
Initialize the loading scene inside our SceneManager, inside createMenuScene()
public void createMenuScene()
{
ResourcesManager.getInstance().loadMenuResources();
menuScene = new MainMenuScene();
loadingScene = new LoadingScene();
SceneManager.getInstance().setScene(menuScene);
disposeSplashScene();
}
That's all for now, we will not use it yet as we will have to create a game scene first, and later code responsible for displaying the loading scene when necessary (see the code diagram to understand when the loading scene will be displayed)
No comments:
Post a Comment