Moving an object by user input

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GKRAFT
    New Member
    • Nov 2008
    • 9

    Moving an object by user input

    I'm looking for a tutorial (preferably with livewires) or some sort of documentation on how to control an object with user input.

    Basically what i want to do is move an object with the arrow keys.

    Any suggestions?
  • boxfish
    Recognized Expert Contributor
    • Mar 2008
    • 469

    #2
    In the book I have, Python for the Absolute Beginner, it's done something like this. The object has a member named screen, which is a reference to the main Screen object.
    Code:
    def moved(self):
        x, y = self.get_pos()
        if self.screen.is_pressed(games.K_LEFT):
            x -= 1
        if self.screen.is_pressed(games.K_UP):
            y -= 1
        if self.screen.is_pressed(games.K_RIGHT):
            x += 1
        if self.screen.is_pressed(games.K_DOWN):
            y += 1
        self.move_to(x, y)
    I hope this helps.

    Comment

    • GKRAFT
      New Member
      • Nov 2008
      • 9

      #3
      Used that code and added

      self.init_mover (dx=0, dy=0)

      and it works perfectly.

      Thanks man!

      Comment

      Working...