View Single Post
  #2  
Old 02-26-2008, 10:31 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
You are using the vizact.onpick function incorrectly. Here is a sample script that shows how to use it. Clicking a box will slide it to the other side of the screen and set the volume up.
Code:
import viz
viz.go()

viz.clearcolor(viz.GRAY)
viz.mouse(viz.OFF)

#Array of sounds
FILES = ['bounce.wav','carousel.wav','bach_air.mid']

def ToggleBox(box):
	box.active = not box.active
	if box.active:
		box.runAction(vizact.moveTo(pos=box.onPos,speed=20))
		box.audio.volume(1)
	else:
		box.runAction(vizact.moveTo(pos=box.offPos,speed=20))
		box.audio.volume(0)

#Create boxes
boxes = []
for i,f in enumerate(FILES):
	box = viz.add('box.wrl')
	box.audio = viz.addAudio(f,loop=True,volume=0.0)
	box.active = False
	box.offPos = (-2,i*2,10)
	box.onPos = (2,i*2,10)
	box.setPosition(box.offPos)
	vizact.onpick(box,ToggleBox,box)
	boxes.append(box)

#Start sounds
for b in boxes:
	b.audio.play()
Reply With Quote