By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,898 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,898 IT Pros & Developers. It's quick & easy.

Moving an object by user input

P: 9
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
Share this Question
Share on Google+
2 Replies


boxfish
Expert 100+
P: 469
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)
  12.  
I hope this helps.
Mar 10 '09 #2

P: 9
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.