This is a fun and simple tutorial for game developers since we are going to build a wheel of fortune game. Let’s get started!
1. Create a Luck class for the main logic
Luck class is inherited from container
2. Data initialization
3. Create a red button to spin (creatbtn)
Center the button: change the default anchor point of the button in the upper left corner to the center of the button this.btn.anchorOffsetX = this.btn.width / 2; this.btn.anchorOffsetY = this.btn.height / 2; Then make the button position in the center of the entire stage. However, the width and height of the stage cannot be obtained by directly using this.stage.stageWidth since there is nothing on the stage when the button is created. As such, students can create a date class to store global data. In this tutorial, two static attributes STAGEWIDTH and STAGEHEIGHT are directly added to main.ts. The specific methods are as follows:
4. Arrange all the prizes in a circle
You will get the prompt when using comments with /***/. When there are many parameters, you can use @param in the comment line to declare the function of each parameter.
5. Respond to click events
Remove the monitoring of the current click in the ‘click’ event to prevent multiple clicks on button.
In the timer, you can directly use timer.delay to change the delay of the timer in milliseconds.
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/