Dec-08-2017, 10:13 PM
(This post was last modified: Dec-08-2017, 10:13 PM by jakegold98.)
DELETE THIS THREAD PLEASE I SOLVED THE ISSUE MY OWN EASY MISTAKE
For some reason the spaceship only moves when I press L or R arrow keys but they should be moving when I hold them down instead of pressing them a bunch of times. here is the code I have I am following metulburr tutorial on part 3. I added the ship.png so you could see for yourself.
For some reason the spaceship only moves when I press L or R arrow keys but they should be moving when I hold them down instead of pressing them a bunch of times. here is the code I have I am following metulburr tutorial on part 3. I added the ship.png so you could see for yourself.
import sys import pygame as pg pg.init() screen_width = 800 screen_height = 600 class player: def __init__(self, screen_rect): self.image = pg.image.load('ship.png').convert() self.image.set_colorkey((255,0,255)) self.transformed_image = pg.transform.rotate(self.image, 180) self.rect = self.image.get_rect(center = screen_rect.center) self.speed = 5 def update(self, keys): if keys[pg.K_LEFT]: self.rect.x -= self.speed elif keys[pg.K_RIGHT]: self.rect.x += self.speed def draw(self, surf): surf.blit(self.transformed_image, self.rect) screen = pg.display.set_mode((screen_width, screen_height)) screen_rect = screen.get_rect() player = player(screen_rect) clock = pg.time.Clock() gameOver = False while not gameOver: screen.fill((0,0,0)) keys = pg.key.get_pressed() for event in pg.event.get(): if event.type == pg.QUIT: gameOver = True player.update(keys) player.draw(screen) pg.display.update() clock.tick(60) player.draw(screen) pg.display.update() pg.quit() sys.exit()