Computer Science Canada Moving Images with arrow keys (while doing other stuff) |
Author: | supaphreek [ Mon Jan 24, 2011 6:20 pm ] | ||
Post subject: | Moving Images with arrow keys (while doing other stuff) | ||
So, as the title says, but to elaborate. Im making a game in which an image has to move... The thing is, the image always has to be moving (and i have the code to set it to keep going) the problem is, the code i found to use arrows is as follows
So, this does the job and makes the image move when i press a key... But what i want it to do is always run the code imgblue.top = imgblue.top - 1... at all times how can i do that? Thanks |
Author: | z_cross_fire [ Wed Feb 02, 2011 7:01 pm ] |
Post subject: | RE:Moving Images with arrow keys (while doing other stuff) |
Do you mean you want something like this: Press Up: The Image keeps moving upwards until another key is pressed... Is that what you want? Can you please explain what you need to do? |
Author: | Insectoid [ Wed Feb 02, 2011 7:08 pm ] | ||
Post subject: | RE:Moving Images with arrow keys (while doing other stuff) | ||
You need a direction flag, most easily consisting of 2 'velocity' variables- X and Y. When someone hits the 'up' key, set the Y velocity to '1' and X to '0'. when someone hits the left key, set X to -1 and Y to 0, etc. Then every time the main loop iterates, add the X and Y flags to the X and Y coordinates. For example,
|