Closed Thread
Results 1 to 2 of 2

Thread: [Pygame] How do i use the keypressing events

  1. #1
    xZachtmx is offline Newbie
    Join Date
    Jun 2009
    Posts
    3
    Rep Power
    0

    [Pygame] How do i use the keypressing events

    ok i have this code so far
    Code:
    import pygame
    from pygame.locals import*
    pygame.init()
    
    
    
    gamePlaying = True
    
    
    
    shipPos = 512,333
    
     
    #while gamePlaying:
     
        # initializing the game window
    gameWindow = pygame.display.set_mode((1024, 768), FULLSCREEN ) 
    pygame.display.set_caption('STARBOUND') 
    screen = pygame.display.get_surface() 
    
    
    #loading textures
        # ship sprites
    podTex = 'shipPlaceholder.png'
    podSprite = pygame.image.load(podTex).convert_alpha()
    
    
    keyBState = pygame.event.get()
        
    
      
    
    
    #drawing code
    screen.blit(podSprite, (shipPos))
    
    pygame.display.update()

    so i want to make the little sprite i have move when a key is pressed but im not sure now... i just want to know the code i alredy know how to make it's position changed when the event happenes
    Last edited by WingedPanther; 06-13-2009 at 12:29 PM. Reason: add code tags (the # button)

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    ShadenSmith's Avatar
    ShadenSmith is offline Newbie
    Join Date
    May 2009
    Location
    Kentucky - USA
    Posts
    19
    Rep Power
    10

    Re: [Pygame] How do i use the keypressing events

    Code:
    for event in keyBState:
        if event.type == KEYDOWN:         
             if (event.key == K_LEFT):
                  //move ship left
    You may also want to look at KEYUP vs. KEYDOWN to see which would better suit your needs.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. mouse events or any events in if statements
    By Siten0308 in forum C# Programming
    Replies: 6
    Last Post: 07-30-2009, 04:42 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts