- Canvas games are basically pixel control, and are an update-> clear-> draw-> wait loop.
- Use an object-oriented system to manage display units and stages.
- Use the Event System to separate the game logic. (In particular, you can handle the status of Multiple game objects at the right time, such as bee colony redirection)
- Use the simplest data structure to represent and manage bee clusters.
- Keyboard Input Processing and status management. (How to lock each frame, how to make the multi-Key press not conflict, such as opening fire and moving)
- Visual residual. (Objects in motion, even a point, will become a line)
- Filter consecutive function calls. (Throttle processing options: 1) Synchronous 2) asynchronous)
- Make the frame rate variable at runtime. (Use requestanimationframe to improve performance first)
- How to get a speed unrelated to the frame rate. (The speed of change, associated with time, calculates the time difference between each frame)
- Use the save, translate, rotate, and restore methods of the canvas as much as possible.
Click to try
@ 2011-10-09 the old version is in trial. I rewrote it and saved it on GitHub.