twisted1230
Still Fresh
- Joined
- Mar 6, 2012
- Messages
- 2
Hello, I'm currently in process of learning Pygame and Python and I'm trying to make a sprite move diagonally across the screen. Although it does work to move the sprite, this code ends up 'painting' the screen when I try to move it diagonally. Is there any way I can fix that?
import pygame, sys, time
from pygame.locals import *
pygame.init()
pygame.display.init()
screen=pygame.display.set_mode ((800,600))
clock=pygame.time.Clock()
image = 'image.png'
Image = pygame.image.load(image).convert_alpha()
x,y=0,0
movex, movey,=0,0
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key==K_LEFT:
movex=-1
elif event.key==K_RIGHT:
movex=1
elif event.key==K_UP:
movey=-1
elif event.key==K_DOWN:
movey=1
if event.type == KEYUP:
if event.key==K_LEFT:
movex=0
elif event.key==K_RIGHT:
movex=0
elif event.key==K_UP:
movey=0
elif event.key==K_DOWN:
movey=0
x = x+movex
y = y+movey
screen.blit(Image,(x,y))
pygame.display.update()
import pygame, sys, time
from pygame.locals import *
pygame.init()
pygame.display.init()
screen=pygame.display.set_mode ((800,600))
clock=pygame.time.Clock()
image = 'image.png'
Image = pygame.image.load(image).convert_alpha()
x,y=0,0
movex, movey,=0,0
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key==K_LEFT:
movex=-1
elif event.key==K_RIGHT:
movex=1
elif event.key==K_UP:
movey=-1
elif event.key==K_DOWN:
movey=1
if event.type == KEYUP:
if event.key==K_LEFT:
movex=0
elif event.key==K_RIGHT:
movex=0
elif event.key==K_UP:
movey=0
elif event.key==K_DOWN:
movey=0
x = x+movex
y = y+movey
screen.blit(Image,(x,y))
pygame.display.update()