Pygame의 그림 배경에 선을 그리는 방법
문제
나는 피그 게임의 표면에 선 (임의 위치와 길이)을 그 자체로 그리기를 원합니다.이 자체는 디스크의 파일에서로드 된 이미지입니다.
누구든지 이것을하는 예제 코드를 알려줄 수 있습니까?
해결책
이것은 당신이 요구하는 일을해야합니다.
# load the image
image = pygame.image.load("some_image.png")
# draw a yellow line on the image
pygame.draw.line(image, (255, 255, 0), (0, 0), (100, 100))
일반적으로 원본 이미지를 그리지 않습니다. 원본을 다시 가져 가려면 이미지를 다시로드해야하므로 (또는 그 위에 그리기 전에 사본을 만들어야합니다). 아마도 당신이 실제로 필요한 것은 다음과 같습니다.
# initialize pygame and screen
import pygame
pygame.init()
screen = pygame.display.set_mode((720, 576))
# Draw the image to the screen
screen.blit(image, (0, 0))
# Draw a line on top of the image on the screen
pygame.draw.line(screen, (255, 255, 255), (0, 0), (50, 50))
다른 팁
pygame의 module pygame.raw에 대한 도움말 :
이름 pygame.draw -그림 모양을위한 pygame 모듈
파일 d : program files python25 lib site-packages pygame draw.pyd
함수 Aaline (...) pygame.draw.aaline (표면, 색상, 스타트 포, 엔드 포스, 블렌드 = 1) : 리턴 낙타 미세한 항아리아 선 라인
aalines(...)
pygame.draw.aalines(Surface, color, closed, pointlist, blend=1): return Rect
arc(...)
pygame.draw.arc(Surface, color, Rect, start_angle, stop_angle, width=1): return Rect
draw a partial section of an ellipse
circle(...)
pygame.draw.circle(Surface, color, pos, radius, width=0): return Rect
draw a circle around a point
ellipse(...)
pygame.draw.ellipse(Surface, color, Rect, width=0): return Rect
draw a round shape inside a rectangle
line(...)
pygame.draw.line(Surface, color, start_pos, end_pos, width=1): return Rect
draw a straight line segment
lines(...)
pygame.draw.lines(Surface, color, closed, pointlist, width=1): return Rect
draw multiple contiguous line segments
polygon(...)
pygame.draw.polygon(Surface, color, pointlist, width=0): return Rect
draw a shape with any number of sides
rect(...)
pygame.draw.rect(Surface, color, Rect, width=0): return Rect
draw a rectangle shape
제휴하지 않습니다 StackOverflow