- Hands-On Game Development with WebAssembly
- Rick Battagline
- 208字
- 2021-06-24 13:41:09
Understanding the game loop
A key concept in game design is the game loop. In any game, the code must run over and over again, performing a series of tasks such as input, AI, physics, and rendering. A game loop might look something like this:
while(loop_forever) {
get_user_input();
move_game_objects();
collision_detection();
render_game_objects();
play_audio();
}
An SDL/C++ game targeting almost any platform except WebAssembly would have a while loop, probably located within the main function of the C++ code, that would exit only when the player exits the game. WebAssembly shares its runtime with the JavaScript engine inside your web browser. The JavaScript engine runs on a single thread, and Emscripten uses JavaScript glue code to take what you have done inside SDL within WebAssembly and render that to the HTML canvas element. Therefore, we need to use an Emscripten-specific piece of code for our game loop:
emscripten_set_main_loop(game_loop, 0, 0);
In the next few chapters, we will be adding some of these functions to our game:
- Game object management
- Collision detection between game objects
- Particle systems
- Enemy spaceship AI using a finite state machine (FSM)
- Game camera for tracking our player
- Play audio and sound effects
- Game physics
- User interface
These will be functions called from the game loop.
- Learning SQL Server Reporting Services 2012
- 施耐德SoMachine控制器應(yīng)用及編程指南
- 計算機組裝·維護與故障排除
- 硬件產(chǎn)品經(jīng)理手冊:手把手構(gòu)建智能硬件產(chǎn)品
- Mastering Adobe Photoshop Elements
- VCD、DVD原理與維修
- 微軟互聯(lián)網(wǎng)信息服務(wù)(IIS)最佳實踐 (微軟技術(shù)開發(fā)者叢書)
- Hands-On Artificial Intelligence for Banking
- 微型計算機系統(tǒng)原理及應(yīng)用:國產(chǎn)龍芯處理器的軟件和硬件集成(基礎(chǔ)篇)
- 筆記本電腦維修實踐教程
- Source SDK Game Development Essentials
- 單片機技術(shù)及應(yīng)用
- WebGL Hotshot
- 新編電腦組裝與硬件維修從入門到精通
- FPGA實驗實訓教程