在平台遊戲中,將滾動添加到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