Pygame - Max OS X screen resolution and moving an image
Hello I am trying to follow the Pygame course, and I stumbled upon an issue with the screen resolution. On lesson 1, we set up the screen resolution to width 800, height 600 on lesson 3, we are going to move the racing car with: x = (display_width * 0.45) y = (display_height * 0.8)
I have an issue with that, I had to reset the x, and y to fit the car on the surface, yet the left right arrow moves the window not to car because I think that the surface is not correctly setup ... can you please help ...
#define colors - RGB black = (0,0,0) white = (255,255,255) red = (255,0,0)
#setup a window also called surface or frame and its resolution gameDisplay = pygame.display.set_mode((display_width,display_height)) #screen resolution pygame.display.set_caption('A bit Racey')
clock = pygame.time.Clock() #specific game clock
#load image carImg = pygame.image.load('racecar.png') #display the image
def car(x,y): gameDisplay.blit(carImg,(x,y)) #blit = copy to
x = (display_width*0.00000000000000001) y = (display_height*0.00000000000000001) x_change = 0 y_change = 0
#game loop - logic for your game crashed = False
while not crashed: for event in pygame.event.get(): if event.type == pygame.QUIT: crashed = True
if event.type == pygame.KEYDOWN: #key pressed if event.key == pygame.K_LEFT: x_change = -5 elif event.key == pygame.K_RIGHT: x_change = 5
if event.type == pygame.KEYUP: #key released if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: x_change = 0
x += x_change
gameDisplay.fill(white) car(x,y)
pygame.display.update() # update the entire window
clock.tick(60) # frame per seconds
pygame.quit() quit()
You must be logged in to post. Please login or register an account.
So are you saying the left and right arrows do not move the car for you?
May be a mac-specific thing, which I cannot really help with unfortunately. I just copy and pasted your code from here and had no noticeable issues.
-Harrison 9 years ago
You must be logged in to post. Please login or register an account.