javascript - How to write the logic and code for the layered rendering of objects and characters in the game?
女神的闺蜜爱上我
女神的闺蜜爱上我 2017-06-26 10:52:05
0
2
912

For example, in the Lone Gunman, the character is sometimes under a tree and sometimes on the grass. They are all objects in the game world. How is the hierarchical logic between the character and the map object handled, and how can the code be optimized?

女神的闺蜜爱上我
女神的闺蜜爱上我

reply all(2)
習慣沉默

Games are generally drawn in a loop. My opinion is to create a classification object at the beginning, for example:

var saves = {
    "background" : [],
    "foreground" :[],
    "characters" : [],
    "ui" : [],
};

Just start in the order of for...in.
For 3D, it may be easier to work with because of the z coordinate. For 2D, since the canvas drawing mechanism is "the picture drawn later covers the picture drawn before", so it needs to be sorted to sort out the hierarchy.

Looking forward to a better answer downstairs. I am not a game developer, I just tried it out of interest.
This is one of my demos

迷茫

The person above is right, the game is based on frame animation, and in each frame, the level of the object can be reset

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template