Director Xtras Joystick.x32 控制游戏手柄
这样就可以开发那种单机游戏了 函数很简单
global joystick
on beginSprite
on fixedWidthNumber(iNumber, iWidth) string
repeat while length(sNumber) < iWidth
return sNumber
on exitFrame me
-- 显示方向键的位置
pointX = joystick.xPos() / 512.0
joystick = xtra("joystick").new()
joystick.useJoy(1) -- 使用第一个手柄
end
sNumber = string(iNumber)
sNumber = "0" & sNumber
end repeat
end
-- 显示按下的按扭
i = 1
s = ""
repeat while i <= 32
if joystick.button(i) then
s = s & "[" & fixedWidthNumber(i,2) & "]"
else
s = s & " " & fixedWidthNumber(i,2) & " "
end if
if (i = 8) or (i = 16) or (i = 24) then
s = s & RETURN
end if
i = i + 1
end repeat
member("buttons").text = s
s = ""
s = s & "x = " & joystick.xPos() & RETURN
s = s & "y = " & joystick.yPos() & RETURN
s = s & "z = " & joystick.zPos()
member("axeposition").text = s
pointY = joystick.yPos() / 512.0
shapeSize = 5
member("axePos").image.fill(0,0,128,128,rgb(0,255,0))
member("axePos").image.draw(pointX - shapeSize, pointY - shapeSize, pointX + shapeSize, pointY + shapeSize, [#shapeType:#oval, #lineSize:2, #color: rgb(150, 0, 0)])
-- 显示一些其他信息
s = ""
s = s & "Number of Joysticks = " & joystick.numberOfJoy() & RETURN
s = s & "Axe Count = " & joystick.axeCount() & RETURN
s = s & "Button Count = " & joystick.buttonCount()
member("misc").text = s
go the frame
end
评论Feed: http://www.ccloveaa.com/blog/feed.asp?q=comment&id=162
Contact Way:QQ:58920142 MSN:ccloveaa@sina.com
李连杰->壹基金->民间后援团!






