CONNEXION
  • RetourJeux
    • Sorties
    • Hit Parade
    • Les + populaires
    • Les + attendus
    • Soluces
    • Tous les Jeux
    • Gaming
  • RetourActu Gaming
    • News
    • Astuces
    • Tests
    • Previews
    • Toute l'actu gaming
  • RetourBons plans
    • Bons plans
    • Bons plans Smartphone
    • Bons plans Hardware
    • Bons plans Image et Son
    • Bons plans Amazon
    • Bons plans Cdiscount
    • Bons plans Decathlon
    • Bons plans Fnac
    • Tous les Bons plans
  • RetourJVTech
    • Actus High-Tech
    • Intelligence Artificielle
    • Smartphones
    • Mobilité urbaine
    • Hardware
    • Image et son
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTech
  • RetourCulture
    • Actus Culture
    • Culture
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch 2
    • Xbox Series
    • Switch
    • Pokemon pocket
    • FC 25 Ultimate Team
    • League of Legends
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • Switch 2
  • PS4
  • One
  • Switch
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Liste des sujets

[PYTHON] Help

Mouig
Mouig
Niveau 6
17 août 2020 à 18:16:58
import sys
import pygame
from pygame.locals import *

pygame.init()
screen = pygame.display.set_mode((640, 480))

black = (255, 255, 255)

blue = (0,0,255)
radius = 64
width = 10
getCenter = screen.get_rect()
pos_y = 0

clock = pygame.time.Clock()

while True:
    touched = False
    for ev in pygame.event.get():
        if ev.type == QUIT:
        	pygame.quit()
        elif ev.type == MOUSEBUTTONDOWN:
        	touched = True
    while touched:
    	for ev in pygame.event.get():
    		if ev.type == MOUSEBUTTONUP:
    			touched = False
    	screen.fill(black)
    	pygame.draw.circle(screen, blue,(getCenter.w / 2, getCenter.h / 1.5 +pos_y), radius, width)
    	clock.tick(60)
    	pygame.display.flip()
    	pos_y -= 1	
    screen.fill(black)
    pygame.draw.circle(screen, blue, (getCenter.w / 2, getCenter.h / 1.5 + pos_y), radius, width)
    pos_y += 1
    clock.tick(60)
    pygame.display.flip()

J'ai commencé a travailler sur ce programme sur un IDE python sur android mais aujourd'hui je l'ai copier coller sur mon ordi car c'est quand meme plus simple :hap:
Seulement voila, alors que le programme fonctionnait parfaitement sur mon téléphone, sur pc il m'envoie une erreur :-(

pygame.draw.circle(screen, blue, (getCenter.w / 2, getCenter.h / 1.5 + pos_y), radius, width)

C'est cette ligne qui pose problème l'erreur étant: "TypeError: integer argument expected, got float"

Malgré des dizaines de tentatives je ne comprend toujours pas le problème :-((

cybevil
cybevil
Niveau 27
17 août 2020 à 19:15:14

C'est assez explicite pourtant un des arguments de la fonction attend un integer mais tu lui donnes un float.

Apparemment c'est le 3ème argument de "pygame.draw.circle()" qui n'accepte que des integers.
Ce qui est bizarre car dans la doc il est indiqué qu'il accepte aussi les floats.

import sys
import pygame
from pygame.locals import *

pygame.init()
screen = pygame.display.set_mode((640, 480))

black = (255, 255, 255)

blue = (0,0,255)
radius = 64
width = 10
getCenter = screen.get_rect()
pos_y = 0

clock = pygame.time.Clock()

while True:
    touched = False
    for ev in pygame.event.get():
        if ev.type == QUIT:
            pygame.quit()
        elif ev.type == MOUSEBUTTONDOWN:
            touched = True
    while touched:
        for ev in pygame.event.get():
            if ev.type == MOUSEBUTTONUP:
                touched = False
        screen.fill(black)
        pygame.draw.circle(screen, blue,( int(getCenter.w / 2), int(getCenter.h / 1.5 +pos_y) ), radius, width)
        clock.tick(60)
        pygame.display.flip()
        pos_y -= 1  
    screen.fill(black)
    pygame.draw.circle(screen, blue, ( int(getCenter.w / 2), int(getCenter.h / 1.5 + pos_y) ), radius, width)
    pos_y += 1
    clock.tick(60)
    pygame.display.flip()
Message édité le 17 août 2020 à 19:19:56 par cybevil
Sous forums
  • Aide à l'achat Mac
  • Steam Deck
  • Création de sites web
  • Création de Jeux
  • Linux
  • Programmation
  • Internet
  • Macintosh
  • Hardware
La vidéo du moment