Joystick Help
Author |
Message |
GillaMobster
|
Posted: Fri Oct 22, 2004 4:16 pm Post subject: Joystick Help |
|
|
Okay, call me useless but I've tried the help menu in turing and I've searched joystick on this site, but I can't seem to get this to work.
Could someone please explain, clearly, how to use the joystick, and also an example of...... say, moving a sprite around the screen with it.
thank you |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Dan

|
Posted: Fri Oct 22, 2004 5:11 pm Post subject: (No subject) |
|
|
what verson of turing are u using b/c there are no bulit in sprites in turing 4.x.
Also i am not shure if the joysitck comands work or not b/c i do not have a wroking joystick to test it on.
This is the exmaple holth gives:
code: |
% The "JoyStick" program.
var jx, jy, x, y, ox, oy : int := - 20
var b1, b2, ob1, ob2 : boolean := false
loop
Joystick.GetInfo (joyStick1, jx, jy, b1, b2)
x := round (maxx * (jx - joyMin) / (joyMax - joyMin))
y := round (maxy * (jy - joyMax) / (joyMax - joyMin))
if x not= ox or y not= oy or b1 not= ob1 or b2 not= ob2 then
Text.Locate (1, 1)
put x : 4, " ", y : 4, " ", b1, " ", b2
Draw.Line (ox - 10, oy, ox + 10, oy, colorbg)
Draw.Line (ox, oy - 10, ox, oy + 10, colorbg)
Draw.Line (x - 10, y, x + 10, y, red)
Draw.Line (x, y - 10, x, y + 10, red)
ox := x
oy := y
ob1 := b1
ob2 := b2
end if
end loop
|
it whould seem it works much like the mouse comands, may be if u posted your code, we could help more.... |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
 |
GillaMobster
|
Posted: Fri Oct 22, 2004 5:25 pm Post subject: (No subject) |
|
|
sorry for not being too clear,
I'm using version 4.0.5, the latest I believe.
And sorry about the sprite thingy, I guess I use a different lingo than you by sprite I mean any .bmp file that you use, I just do:
var pic1 :int
pic1 := Pic.FileNew("pic1.bmp")
then
Pic.Draw (pic1, x, y6, picMerge)
whereever I need to use it.
So anyways I just want to move this .bmp around using the joystick, but I cant seem to get it to work using the example you posted from the help file, so if there is any one that has source code that can do this please show me the example.
Thank you. |
|
|
|
|
 |
Delos

|
Posted: Fri Oct 22, 2004 9:31 pm Post subject: (No subject) |
|
|
Ok, let's clarify this. When you use the Joystick() functions, do they return accurate values?
If so, then you simply need to take the values returned from Joystick.GetInfo() and use these as your xy coords for your picture.
code: |
var joyX, joyY, joyB1, joyB2 : int
var pic : int
pic := Pic.New ("aPicture.bmp")
loop
Joystick.GetInfo (joyX, joyX, joyB1, joyB2)
Pic.Draw (pic, joyX, joyY, picCopy)
delay (10)
cls
exit when hasch
end loop
|
|
|
|
|
|
 |
GillaMobster
|
Posted: Sat Oct 23, 2004 12:50 am Post subject: (No subject) |
|
|
Im sorry i tried it and it's still not working,
If anyone has ever written any code that uses the joystick to move something around on the screen, could you please post it.
Or if any has the time could you write up a quick 20 line something program that does this so I can see a working example.
thankyou |
|
|
|
|
 |
Tony

|
Posted: Sat Oct 23, 2004 1:01 am Post subject: (No subject) |
|
|
eh... new approach
code: |
var joyX, joyY, joyB1, joyB2 : int
loop
Joystick.GetInfo (joyX, joyY, joyB1, joyB2)
locate(1,1)
put joyX, " ", joyY, " ", joyB1, " ", joyB2
delay(10)
exit when hasch
end loop
|
what shows up on the screen when you move the joystick around? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
GillaMobster
|
Posted: Sat Oct 23, 2004 1:39 pm Post subject: (No subject) |
|
|
Okay thanks for taking the time to help me out,
I had to make some little changes to get the code to compile
code: |
var joyX, joyY : int
var joyB1, joyB2 : boolean := false
loop
Joystick.GetInfo (0, joyX, joyY, joyB1, joyB2)
locate (1, 1)
put joyX, " ", joyY, " ", joyB1, " ", joyB2
delay (10)
exit when hasch
end loop
|
joyB1 and joyB2 have to be boolean's and are false unless u press either button one or two.
also I had to but a 0 in before JoyX, I'm pretty sure this tells it to get the input from the first joystick, other wise it doesn't compile without these changes.
and the out put:
I if I press left on the joystick I get
-4961 0 false false
If I press right:
4961 0 false false
if I press up:
0 4961 false false
if I press down:
0 -4961 false false
If I press button 1:
0 0 true false
if I press button 2:
0 0 false true |
|
|
|
|
 |
GillaMobster
|
Posted: Mon Oct 25, 2004 2:48 pm Post subject: (No subject) |
|
|
Okay, no offense but it doesn't look like anybody here as used the joystick, so is there any other TURING websites that you guys know of that might be able to help me out? |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Mazer

|
Posted: Mon Oct 25, 2004 3:06 pm Post subject: (No subject) |
|
|
The code works for me. Of course, I'm trying this on a gamepad, so I only get values between +/- ~4900 to +/- 5000 instead of the wider variety of values I'd expect from an actual joystick or other analog device.
The zero you supply as the first parameter to Joystick.GetInfo is just a constant integer. You could use the predefined constants joystick1 or joystick2 as mentioned in the turing reference.
As for the thing about other turing sites. The just seem to fade away. Before this, there was BJWebber's message board. And a couple of years ago there was ooturing.psychz.net or something like that, but they are gone as well. I remember a while ago they emailed NeonHelium and he put a link to their site on nehe.gamedev.net. I found that rather funny. But again, they're gone.
And to be honest, since shortly after this site started, it was the most comprehensive turing resource I've ever known.
P.S. to everybody else posting code and passing 4 parameters to Joystick.GetInfo: did you even read the reference?
EDIT: Hmm... this joystick junk is pretty neat. If I could get more than two buttons, I'd redo EM for it. |
|
|
|
|
 |
Mazer

|
Posted: Mon Oct 25, 2004 3:48 pm Post subject: (No subject) |
|
|
Oh snap, I got it.
I can get the joystick working with multiple buttons, although it's not very nice and simple, as it involves replacing/editing the joystick.tu file. I might write up my own wrapper procedures for the joystick to give you variable button support later on (even though it'll likely go unused). |
|
|
|
|
 |
GillaMobster
|
Posted: Thu Nov 11, 2004 6:43 pm Post subject: (No subject) |
|
|
Hey, I finally figured out how to get this working.
After coming back to this old topic and carefully reading and experimenting with everything said here I finally found a way to get it to work.
Sadly it's not really how the help file or anyone else said and it seems kinda messy but heres the code.
code: |
var win := Window.Open ("graphics:max;max,nobuttonbar")
View.Set ("offscreenonly")
var joyX, joyY, x, y : int := 0
var joyB1, joyB2 : boolean := false
var pic : int
pic := Pic.FileNew ("Pic1.bmp")
loop
cls
Joystick.GetInfo (joystick1, joyX, joyY, joyB1, joyB2)
if joyX = 4961 then
x += 3
elsif joyX = -4961 then
x -= 3
end if
if joyY = 4961 then
y += 3
elsif joyY = -4961 then
y -= 3
end if
joyX := 0
joyY := 0
Pic.Draw (pic, x, y, picCopy)
View.Update
delay (50)
end loop
|
Any comments or anything feel free to respond. |
|
|
|
|
 |
GillaMobster
|
Posted: Fri Nov 12, 2004 12:39 am Post subject: (No subject) |
|
|
Okay I've fiddeled around with this and even went into the Joystick.tu file like the other guy and figured out how to get the other buttons working.
It's not too messy, add/change 3 lines in the Joystick.tu file and and an extra parameter in your control program to accomadate.
Anyways since I had such trouble getting this to work and not many people were able to offer much help, that I could get to work anyways, I'm going to write my first Tutorial on all this, whish me luck! |
|
|
|
|
 |
|
|