WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-06-2010, 07:42 AM
jaffaaswami jaffaaswami is offline
Member
 
Join Date: Oct 2010
Posts: 5
assigning the mouse functionality to Keyboard events

Hi all,

I am beginner to game development and 3D environment. Recently I have gone through some tutorials(world demos) in viz and found the "duck court" demo interesting. I want to make a change to the existing code. Instead of using a mouse to target the ducks, I want the keyboard arrow keys to take care of that..

The code for the mouse looks like this:

#Add a crosshair that is linked to the mouse
viz.link(viz.Mouse , viz.addTexQuad(viz.SCREEN,texture=viz.add('crossha ir.png')) )

How should I assign the same to keyboard arrow keys. So that the crosshair moves all around the screen. Thanks in advance. You all have a great day ahead.

Thank & Regards,
Swami
Reply With Quote
  #2  
Old 10-07-2010, 06:56 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
You could update the crosshair position when a key event occurs:
Code:
import viz
viz.go()

court = viz.add('court.ive')
target = viz.addTexQuad(viz.SCREEN,texture=viz.add('crosshair.png'))
target.setPosition(0.5,0.5)

vizact.whilekeydown( viz.KEY_UP, target.setPosition, [0, vizact.elapsed(0.2),0], viz.REL_PARENT )
vizact.whilekeydown( viz.KEY_DOWN, target.setPosition, [0, vizact.elapsed(-0.2), 0], viz.REL_PARENT )
vizact.whilekeydown( viz.KEY_RIGHT, target.setPosition, [vizact.elapsed(0.2), 0, 0], viz.REL_PARENT )
vizact.whilekeydown( viz.KEY_LEFT, target.setPosition, [vizact.elapsed(-0.2), 0, 0], viz.REL_PARENT )
Reply With Quote
  #3  
Old 10-07-2010, 11:58 PM
jaffaaswami jaffaaswami is offline
Member
 
Join Date: Oct 2010
Posts: 5
Hey Jeff,

Thanks a lot for the suggestion. It works awesome... I really appreciate your help. Beginners like me need this type of encouragement for showing further interest in the field.
Thanks again.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Warning mouse() -> Set mouse() of window johannes2 Vizard 1 08-19-2010 03:11 PM
how to remove velocity when mouse is disabled? jvacare1 Vizard 2 02-18-2010 11:25 AM
Navigating an avatar using mouse position(2D) in 3D environment james007 Vizard 1 10-16-2009 12:29 PM


All times are GMT -7. The time now is 04:10 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC