471,595 Members | 1,040 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,595 software developers and data experts.

Moving an object by user input

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
2 2482
boxfish
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)
  12.  
I hope this helps.
Mar 10 '09 #2
GKRAFT
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.

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
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.