여기에 내 코드파이 게임 벽 충돌 감지는 "도청"보인다
import pygame, sys
pygame.init() #load pygame modules
size = width, height = 800, 600 #size of window
speed = [25,25] #speed and direction
x= 100
y= 100
screen = pygame.display.set_mode(size) #make window
s=pygame.Surface((50,50)) #create surface 50px by 50px
s.fill((33,66,99)) #color the surface blue
r=s.get_rect() #get the rectangle bounds for the surface
r[0] = x #changes initial x position
r[1] = y #changes initial y position
clock=pygame.time.Clock() #make a clock
while 1: #infinite loop
clock.tick(30) #limit framerate to 30 FPS
for event in pygame.event.get(): #if something clicked
if event.type == pygame.QUIT:#if EXIT clicked
pygame.quit()
sys.exit() #close cleanly
r=r.move(speed) #move the box by the "speed" coordinates
#if we hit a wall, change direction
if r.left <= 0 or r.right >= width:
speed[0] = -(speed[0])*0.9 #reduce x axis "speed" by 10% after hitting
if r.top <= 0 or r.bottom >= height:
speed[1] = -speed[1]*0.9 #reduce y axis "speed" by 10% after hitting
screen.fill((0,0,0)) #make redraw background black
screen.blit(s,r) #render the surface into the rectangle
pygame.display.flip() #update the screen
그것은 가장자리를 치는 다시 수신 거부, 사각형 이동을 보여주는 간단한 창의입니다. 그러나이 특정 예 (속도를 양쪽 축에서 25로 설정)와 속도 감소를 0.9로 설정 한 뒤 되돌리기 (10 % 미만), 내 사각형이 창 왼쪽에 붙어있는 것처럼 보입니다. 붙여 넣기 및 직접 참조하십시오)
내가 낮은 값으로 변경하거나 모든 속도를 줄이면 아무 것도 수신 거부 후 모든 것을 잘 작동합니다.
왜 이런 일이 발생하는지 이유가 무엇입니까?
@dwerner 왜 그런가요? 문서에 달리 명시되어 있습니다. –