So there is my previous code that I corrected myself, but there is another problem. The 'game' is running at 60 FPS, but when I wanna blit a background instead of a black screen, the game slows down to 30 fps.. Is there a way to fix this ?
import math
import pygame
class Planete:
def __init__(self,rayon,periode,envergure,couleur):
self.rayon = rayon
self.periode = periode
self.couleur = couleur
self.envergure = envergure
self.omega = (2*math.pi)/self.periode
self.i = 0
def tourner(self) :
self.x = self.rayon*math.cos(self.omega*self.i)
self.x2 = int(self.x)+500
self.y = self.rayon*math.sin(self.omega*self.i)
self.y2 = int(self.y)+200
self.i = self.i + 1
def dessiner(self):
pygame.draw.circle(gameDisplay,(self.couleur),((self.x2, self.y2)), self.envergure)
pygame.init()
Terre = Planete(149, 65.25,9,(25,0,250))
Mars = Planete(227, 86.98,8,(250,25,0))
#Wuut = Planete(195,206,7,(15,30,70))
#Jupiter = Planete(80,800,12,(150,50,15))
gameDisplay = pygame.display.set_mode((1280,720))
background = pygame.image.load("Ecran titre\\principal\\background.jpg")
menu = pygame.image.load("Ecran titre\\principal\\menu.png")
clock = pygame.time.Clock()
gameExit = False
while not gameExit :
Terre.tourner()
Mars.tourner()
#Wuut.tourner()
#Jupiter.tourner()
for event in pygame.event.get():
if (event.type == pygame.QUIT):
gameExit = True
gameDisplay.fill(0)
#gameDisplay.blit(background,(0,0))
Terre.dessiner()
Mars.dessiner()
#Wuut.dessiner()
#Jupiter.dessiner()
pygame.display.update()
clock.tick(60)
pygame.display.set_caption("fps: " + str(clock.get_fps()))
pygame.quit()
quit()
Blitting an image that has transparency is really slow. If you call .convert() after loading it, it'll make it blit faster. This will convert it to a faster opaque format.
background = pygame.image.load("Ecran titre\\principal\\background.jpg").convert()