在平台游戏中,将滚动添加到pygame
Implementing Scrolling:
To implement scrolling in Pygame, use aCamera class that defines the offset between the game world and the player's position.然后将此偏移量应用于所有游戏实体在屏幕上绘制的所有游戏实体的位置。
确定摄像机如何关注播放器。相机函数:
实现camera_func:class Camera: def __init__(self, camera_func, width, height): self.camera_func = camera_func self.state = Rect(0, 0, width, height) def apply(self, target): return target.rect.move(self.state.topleft) def update(self, target): self.state = self.camera_func(self.state, target.rect)
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3