Home > other >  Of the new required! Game programming guide
Of the new required! Game programming guide

Time:09-27

Game code also wrote a few years, sometimes wonder if now to just into the line yourself a little advice may have a little help, so this article is mainly to share yourself for introduction to game programming ideas,

The choice of language

More in the beginning is recommended from the introduction to a high-level language, such as Java, c #, lua, python, javascript, during this period can cooperate with some game engine to learn, if you because I like the game to learn programming may not like always print some text, may prefer the output images,

Can directly from the corresponding language game engine began to do a few small Demo know about the structure, but the game engine has a malpractice is introductory API too much difficult...

Game engine has the advantage of playing games will be more quickly, but the whole engine is slightly big, not suitable for learning code,

After can use pico - 8, love2d, pygame, SDL or javascript directly operating canvas canvas to challenge myself to make a try to make the game programming ability,

And C (including C + +) can be placed in the follow-up study, study C language can understand what the underlying order of language, as the pointer allows you to directly access memory, which is rare in other languages, may generally feel not to come out of its power, but when you face a resources nervous system (requires manual memory management), e.g. when programming the GBA NDS and is not open around the C language and assembly language,

must start work more

I love reading before not learning to program is a young, so when I was first learning to write code often has been reading without practice, there are some things seem to understand, practical still have to learn to master operation thoroughly,

When set out to write code, preferably with questions to learn programming is dividing complex problems, such as making a small Demo time can consider this a few problems:

How to display a photo/elf
How to play animation to
How to control the two objects collide
When two objects collide destroyed one of the objects at the same time generate a broadcast frame animation effects and then destroyed after completion is played
How to play the music sound
Background layer scrolling effect do
How to deal with the archive (data persistence)

And then consider the question may be:

Elves shows how to points clear after which render first which render (sfumato)
Special effects are generated every time an object is then destroyed a bit waste of memory, once can generate multiple reuse (the introduction of object pool)
Archive time if A written to the file was not over B and written to the file will be A problem (file system is introduced using singleton)


Don't become obsessed with Opengl

Game industry relatively popular graphics, may feel up to, but for beginners (not a beginner) actually more attention should be focused on GamePlay,

I just started writing code in run it didn't take long to get the opengl little red book in eating, wrote a bunch of code in the end also didn't learn anything,

Don't consider 3 d aspect at first, start with simple 2 d is good, this time I recommend to see more code ecru and game artificial intelligence to exercise the ability,

Even if you want to learn graphics Shader, my suggestion is that more direct use Unity top first learn how to write some Shader (recommended Unity Shader and screen effects development tips), can write some more special effects and then go back and write Opengl rendering pipeline that will more feeling,

don't imprison in the game engine

Now the game engine is very convenient, is the purpose of writing software to make it more and more easy to use,

But has been using the game engine for beginners of programming is more difficult to raise the level of programming, personal advice can be starting from the introduction to the game engine, then try to do not use the engine with the above mentioned some underlying framework or tool to make the game,

Build some small wheels to improve

A lot of people say that don't repeat the wheel, but sometimes others wheel is not enough light heavyweight, write for their own lightweight wheels also to have certain to improve their programming ability, also can enjoy the fun of programming, more

Such as the comparison of above mentioned at the bottom of the frame (SDL) to make a game and then write a simple map editor, particle system, the archive file read system or a menu system, although you can't do this with professional engine production than, but one day you have to look back to the engine and then some problems will have a different solution,

pay attention to the application of data structure

When just learning data structure into this stuff in the game development does in doubts, in addition to the common used pathfinding figure and network programming message queue, the other when I started learning data structure all don't know anything,

When stack applications: in the treatment of the menu such as stack into the Settings menu when pressed a new menu operation, return when the stack can be destroyed, in the scene into a game room can suspend in the current game scene then put new pressure stack room scene,

When some need to buffer the input queue applications: (fighting games, for example) can use the queue to control the input operation, the system in some skills such as a round of eight physical slot players to combination attacks, when making playback system can also use the queue to produce,

Tree applications: basic is a branch when you need to face a branch and each branch has time to consider, the typical plot or dialogue trees, for example, there are a lot of child objects under the node, the child object and can have many children when its application scenarios,

Figure applications: in the visualization process control, the finite state machine and navigation system can find its shadow,

the model of game development design

This actually has specifically elaborates the books, I also just teach fish to swim, I only talk about a few for me when beginning more fruitful,

Singleton pattern: when many people began to contact the game engine will face a problem is scene switch does not destroy data, is not recommended practice is also some beginners make is to put the data saved to the local, and then read the next scene, this directly read and write operations and is not an option when you want to save a game object (GameObject) can't when I was (of course also can actually serialized object saved to the local but is still not an option), the more desirable is saved to a static object/global variables, it is introduced the singleton pattern, there are still some systems such as only one entry is not allowed to use it or it will go wrong, such as a typical file IO and controller input control,

Data driven: in Unity ScriptObject obviously is data driven, its core idea is to change data without having to change the code, and when you do use data-driven must points clear what can be what hard coded data driven, configuration too much is very affect the development efficiency and can be read,

Reduce consumption of pointer jump: I think this is one of the reasons, put forward by the ECS in a big game with a huge amount of game objects, the object of the game and at this time there are all sorts of pointer jump performance caused by the consumption cannot be ignored, so when writing code to pay attention to reduce needle jump, as far as possible let memory continuous distribution, such as the use structure and arrays, memory continuous distribution, of course, can also reduce memory fragments,

Prototype patterns: the first appears is seen in Cocos2d - x, an interface to implement the cloning of the current object, in the actual game is also quite common, such as the GBA the konoha us, naruto to use shadow copy generated a new character but damage and blood volume in half, in the Unity of Prefab from the Project window drag the Scene in time also use a similar idea (should),

pay attention to clean code

This is more empirical, so hard to say I did a good job, keep the code readability is come back to you or others in the future to see code can read, it is necessary to keep the function of single responsibility, when you find some code to write a few times you should think about whether it should be in a function, you must understand is that bugs are always available, one day you or someone else will look at the code again, if you pay attention at the time of writing, the maintenance and reuse of late will be relatively simple and easy,

Concrete may have a look the code, the code neat and this video,

Finally, making the game is very interesting, write game code is also very happy, hope you can enjoy the pleasure of game programming!
  • Related