- SFML Game Development By Example
- Raimondas Pupius
- 240字
- 2021-07-23 14:55:08
Hunting bugs
As proud and satisfied as you may be with your first project, nothing is ever perfect. If you've spent some time actually playing the game, you may have noticed an odd event when quickly mashing the buttons, looking something like this:

The image represents the difference between two sequential updates. It seems that earlier it was facing the right direction and then it's facing left and missing its tail. What happened? Try to figure it out on your own before continuing, as it perfectly illustrates the experience of fixing game flaws.
Playing around with it some more reveals certain details that narrow down our problem. Let's break down what happens when a player starts mashing keys quickly:
- The snake is facing right.
- Any arrow key other than the left or right is pressed.
- The direction of the snake gets set to something else, let's say up.
- The right key is pressed before the game has a chance to update.
- Since the snake's direction is no longer set to right or left,
if
statement in the input handler is satisfied and sets the direction to left. - The game updates the snake and moves it left by one space. The head collides with its tail and it gets cut off.
Yes, it seems that our direction checking is flawed and causes this bug. Once again, spend some time trying to think of a way to fix this before moving on.
- JavaScript+DHTML語法與范例詳解詞典
- Java Web基礎與實例教程(第2版·微課版)
- Android NDK Beginner’s Guide
- 你必須知道的204個Visual C++開發問題
- Eclipse Plug-in Development:Beginner's Guide(Second Edition)
- Visual C++應用開發
- Reactive Android Programming
- Java Web程序設計任務教程
- ASP.NET程序開發范例寶典
- Getting Started with Python and Raspberry Pi
- 人工智能算法(卷1):基礎算法
- Practical GIS
- IBM RUP參考與認證指南
- 從“1”開始3D編程
- 優化驅動的設計方法