Home  >  Q&A  >  body text

javascript - What is the principle of background movement in the game?

For example, if a person walks forward and the background moves backward, switch the canvas

巴扎黑巴扎黑2643 days ago969

reply all(2)I'll reply

  • typecho

    typecho2017-06-27 09:20:47

    There can be many implementation principles, which will vary according to the theme and content of the game. The common things I know that are easier to implement:
    1. Set a background image, tile the size of the main game area, set background-repeat to repeat, and change the coordinates of the background-position of the image through a timer (for example The background of the masturbation game on WeChat).
    2. In addition, there are also some backgrounds with relatively complex backgrounds that can be spliced ​​together without gaps in a sub-container containing multiple background images. They can be positioned relative to the parent container, and the top and left values ​​of the sub-container can be changed by moving (similar to carousel images) principle), because people moving forward are actually caused by the movement of the "person" level within a limited area, and at the same time, the ground and background are positioned and moved in the opposite direction of the person at another same level.

    reply
    0
  • 高洛峰

    高洛峰2017-06-27 09:20:47

    My first impression is that of a 2D game like Super Mario. Its background is not continuous in two directions, left and right. I think the stupidest way is that the 2D background is very long, and then the camera keeps moving forward, haha.

    reply
    0
  • Cancelreply