J'essaye de charger une image en vain
Résolu
Clawzix
Messages postés
7
Date d'inscription
Statut
Membre
Dernière intervention
-
Clawzix Messages postés 7 Date d'inscription Statut Membre Dernière intervention -
Clawzix Messages postés 7 Date d'inscription Statut Membre Dernière intervention -
A voir également:
- J'essaye de charger une image en vain
- Image iso - Guide
- Légender une image - Guide
- Transformer une image en icone - Guide
- Acronis true image - Télécharger - Sauvegarde
- Couper une image en 3 instagram - Guide
4 réponses
Bonjour
Non, cette image ne permet pas de t’aider.
Déjà pour poster ton code, il faut faire comme décrit là https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
Et c’est super important en Python, sinon, le site ne conserve pas l’indentation.
Non, cette image ne permet pas de t’aider.
Déjà pour poster ton code, il faut faire comme décrit là https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
Et c’est super important en Python, sinon, le site ne conserve pas l’indentation.
import pygame as p
from Chess import ChessEngine
p.init()
WIDTH = HEIGHT = 512
DIMENSION = 8
SQ_SIZE = HEIGHT // DIMENSION
MAX_FPS = 15
IMAGES = {}
def loadImages():
pieces = ["bB", "bK", "bN", "bp", "bQ", "bR", "wB", "wK", "wN", "wp", "wQ", "wR"]
for piece in pieces:
IMAGES[piece] = p.transform.scale(p.image.load("images/" + piece + ".png"), (SQ_SIZE, SQ_SIZE))
def main():
p.init()
screen = p.display.set_mode((WIDTH, HEIGHT))
clock = p.time.Clock()
screen.fill(p.Color("white"))
gs = ChessEngine.GameState()
loadImages()
running = True
while running:
for e in p.event.get():
if e.type == p.QUIT:
running = False
drawGameState(screen, gs)
clock.tick(MAX_FPS)
p.display.flip()
def drawGameState(screen, gs):
drawBoard(screen)
drawPieces(screen, gs.board)
def drawBoard(screen):
colors = [p.Color("white"), p.Color("gray")]
for r in range(DIMENSION):
for c in range(DIMENSION):
color = colors[((r+c) % 2)]
p.draw.rect(screen, color, p.Rect(c*SQ_SIZE, r*SQ_SIZE, SQ_SIZE, SQ_SIZE))
def drawPieces(screen, board):
for r in range(DIMENSION):
for c in range(DIMENSION):
piece = board[r][c]
if piece != "--":
screen.blit(IMAGES[piece], p.Rect(c*SQ_SIZE, r*SQ_SIZE, SQ_SIZE, SQ_SIZE))
if __name__ == "__main__":
main()
Excuse moi j'aurai du regarder comment faire avant de publier mon problème
from Chess import ChessEngine
p.init()
WIDTH = HEIGHT = 512
DIMENSION = 8
SQ_SIZE = HEIGHT // DIMENSION
MAX_FPS = 15
IMAGES = {}
def loadImages():
pieces = ["bB", "bK", "bN", "bp", "bQ", "bR", "wB", "wK", "wN", "wp", "wQ", "wR"]
for piece in pieces:
IMAGES[piece] = p.transform.scale(p.image.load("images/" + piece + ".png"), (SQ_SIZE, SQ_SIZE))
def main():
p.init()
screen = p.display.set_mode((WIDTH, HEIGHT))
clock = p.time.Clock()
screen.fill(p.Color("white"))
gs = ChessEngine.GameState()
loadImages()
running = True
while running:
for e in p.event.get():
if e.type == p.QUIT:
running = False
drawGameState(screen, gs)
clock.tick(MAX_FPS)
p.display.flip()
def drawGameState(screen, gs):
drawBoard(screen)
drawPieces(screen, gs.board)
def drawBoard(screen):
colors = [p.Color("white"), p.Color("gray")]
for r in range(DIMENSION):
for c in range(DIMENSION):
color = colors[((r+c) % 2)]
p.draw.rect(screen, color, p.Rect(c*SQ_SIZE, r*SQ_SIZE, SQ_SIZE, SQ_SIZE))
def drawPieces(screen, board):
for r in range(DIMENSION):
for c in range(DIMENSION):
piece = board[r][c]
if piece != "--":
screen.blit(IMAGES[piece], p.Rect(c*SQ_SIZE, r*SQ_SIZE, SQ_SIZE, SQ_SIZE))
if __name__ == "__main__":
main()
Excuse moi j'aurai du regarder comment faire avant de publier mon problème
Je comprend que la fonctino p.image.load() n'arrive pas à trouver mon image avec les paramètres que je lui fournis