469,271 Members | 1,537 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

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?
Mar 10 '09 #1
2 2297
469 Expert 256MB
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.
Expand|Select|Wrap|Line Numbers
  1. def moved(self):
  2.     x, y = self.get_pos()
  3.     if self.screen.is_pressed(games.K_LEFT):
  4.         x -= 1
  5.     if self.screen.is_pressed(games.K_UP):
  6.         y -= 1
  7.     if self.screen.is_pressed(games.K_RIGHT):
  8.         x += 1
  9.     if self.screen.is_pressed(games.K_DOWN):
  10.         y += 1
  11.     self.move_to(x, y)
I hope this helps.
Mar 10 '09 #2
Used that code and added

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

and it works perfectly.

Thanks man!
Mar 11 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Woody Splawn | last post: by
1 post views Thread by =?Utf-8?B?UmljaA==?= | last post: by
15 posts views Thread by mcjason | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.