This is the seventh part of Egretia Engine tutorial, showing how to build a space shooter game!
Part 1 https://bit.ly/32xy7r3
Part 2 https://bit.ly/2CV2CfC
Part 3 https://bit.ly/39uicLD
Part 4 https://bit.ly/3jJui8p
Part 5 https://bit.ly/31boR9Q
Part 6 https://bit.ly/31mFM9j
Demonstration
> Implementation of RES resources loading

Main

>Implementation of Resources loading

Main
public menu:MainMenu;
public canvasIndex:number; // Interface index
Construct:
this.game= null;
this.addChild(this.menu);
this.canvasIndex=10; //10menu 20game 30over
Main
Add the following codes to touchdown,touchMove,touchup and update:
switch(this.canvasIndex)
{
case 10:
this.menu.touchDown(e);
break;
case 20:
this.game.touchDown(e);
break;
}
public loadingView;
private async loadResource() {
try {
this.loadingView = new LoadingUI();
this.stage.addChild(this.loadingView);
await RES.loadConfig(“resource/default.res.json”, “resource/”);
//menu belongs to the name of group and its background is saved in its group
await RES.loadGroup(“menu”, 0, this.loadingView); this.stage.removeChild(this.loadingView);
}
catch (e) {
console.error(e);
}
}
Mainmenu
public async touchDown(e:egret.TouchEvent)
{
//=null means there are no constructor or no resources loading. Then the interface starts to load
if(this.main.game == null){ // add the loading interface to the scene
this.stage.addChild(this.main.loadingView);
//read the resources
await RES.loadGroup(“game”, 0, this.main.loadingView);
//remove the interface
this.stage.removeChild(this.main.loadingView);
//construct the game interface after loading
this.main.game = new MainGame(this.main);
}
this.main.removeChild(this);
this.main.game.reset(0); // 0 is the game level
this.main.addChild(this.main.game);
this.main.canvasIndex = 20;
}
Loading
// add the loading interface to scene
this.stage.addChild(this.main.loadingView);
//read the resources
await RES.loadGroup(“game”, 0, this.main.loadingView);
//remove the interface
this.stage.removeChild(this.main.loadingView);
>Add the images in interfaces

Create LoadingUI2

Main
loadResource()
this.loadingView = new LoadingUI2();

MainMenu

> Singleton Pattern and Create JSON
An implementation of the singleton pattern must:
ensure that only one instance of the singleton class ever exists;
and provide global access to that instance.
JSON is an open standard file format, and data interchange format, that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and array data types (or any other serializable value). It is a language-independent data format and a very common data format, with a diverse range of applications.
> Basic concepts of game design and game development:Separate data and logic
{
“playV”: 30, ”:”player’s speed”,
“zdV”: 10, ” :” Bullet rotational speed”
}
Create JSON file and import resources

What are the coolest projects you saw from people using Egretia engine?
Stay tuned for updates from the Egretia official channels below so that you can be involved in all the exciting things to come!
Egretia Telegram: https://t.me/Egretia
Egretia Twitter: https://twitter.com/Egretia_io
Egretia Website: https://egretia.io/