| کانال توسعهدهندگان بازی |
Photo
click to show
click to show
در کد زیر برای پیادهسازی زمانبندی شلیک در یک بازی دوبعدی، از delta time بهصورت نادرست استفاده شده است و ممکن است نرخ شلیک روی سیستمهای مختلف (fpsهای متفاوت) ناسازگار شود:
import pygame
class Player:
def __init__(self):
self.fire_rate = 0.5 # ثانیه بین هر شلیک
self.time_since_last_shot = 0
def update(self, dt):
self.time_since_last_shot += 1 # استفاده اشتباه از dt
def can_shoot(self):
return self.time_since_last_shot >= self.fire_rate
def shoot(self):
if self.can_shoot():
print("Shoot!")
self.time_since_last_shot = 0
clock = pygame.time.Clock()
player = Player()
running = True
while running:
dt = clock.tick(120) / 1000.0 # dt بر حسب ثانیه
player.update(dt)
player.shoot()
در این کد چه چیزی باید اصلاح شود تا زمانبندی شلیک روی fpsهای مختلف یکسان و قابلاعتماد باشد؟
🔖 #GameDev #بازیسازی
👤 Developix
💎 Channel: @DevelopixGame
1 · 362 ·