Add scrolling to a platformer in pygame

前端 未结 4 774
梦如初夏
梦如初夏 2020-11-22 08:09

Ok so I included the code for my project below, I\'m just doing some experimenting with pygame on making a platformer. I\'m trying to figure out how to do some very simple s

4条回答
  •  抹茶落季
    2020-11-22 08:49

    Since right know, you have a static background, and the player that you control, is blitted in the position he is in, you have 2 options to always show the character in the middle.

    1. If you map is small enought, you can have a big img A, and derive a rectangle, based on the position of the player that will be the size of the screen. That way, the player will always be in the middle. A Rect.clamp(Rect) or Rect.clamp_ip(Rect) will aid you in that.

    2. Another approach is to have a different tuple for position on screen. The player will have a constant value in the center of the screen, while the backgrounds position will be the negative of the player position.

提交回复
热议问题