![]() |
#2
|
|||
|
|||
vizact.whilekeydown will be added as events that will listen to the specified keystrokes. When you click the first ball, the events for the first ball will be created. When you click the second ball the events for the second ball will be added to the chain of events that listen to KEY_UP etc. This already includes the events of the first ball since you are creating new events instead of replacing the old.
The ball variable is also in local scope in the mouseclick function so any change you make to it (the assignment of the new ball through ball = viz.pick() for instance) will not affect the global ball variable. What you should do is move the vizact statements out of the function and replace the second argument with a function of your own. This function could handle the translation for you. This way you'll only have 1 event for each key. change the mouseclick function to only handle the picking of a ball Code:
def mouseclick(button): global ball #global reference to the ball if button == viz.MOUSEBUTTON_LEFT: pickObj = viz.pick() if pickObj.valid(): ball = pickObj #assign the current chosen ball to the global variable Code:
vizact.whilekeydown( viz.KEY_UP, myTranslate, viz.KEY_UP ) vizact.whilekeydown( viz.KEY_DOWN, myTranslate, viz.KEY_DOWN ) vizact.whilekeydown( viz.KEY_RIGHT, myTranslate, viz.KEY_RIGHT ) vizact.whilekeydown( viz.KEY_LEFT, myTranslate, viz.KEY_LEFT ) Code:
def myTranslate(key): global ball if not ball: #no ball selected, don't try to translate return else: if key == viz.KEY_UP: #up is being pressed ball.translate #... add the rest of the up translation of the ball here elif key == viz.KEY_DOWN: ball.translate # ... add the rest of the down translation of the ball here elif key == viz.KEY_LEFT: ball.translate # ... add the rest of the left translation of the ball here elif key == viz.KEY_RIGHT: ball.translate # ... add the rest of the right translation of the ball here |
Thread Tools | |
Display Modes | Rate This Thread |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Stop for... loop | Johannes | Vizard | 20 | 04-01-2014 01:53 AM |
How to stop vizact.move | Jerry | Vizard | 3 | 06-04-2009 04:25 PM |
delays with <avatar>.act and speech | vsully | Vizard | 15 | 08-23-2007 04:24 PM |
When a video stop ? | djdesmangles | Vizard | 2 | 01-11-2007 04:15 PM |
download problems & avatar action | vgracie | Vizard | 1 | 09-14-2006 11:29 AM |