Director Xtras Joystick.x32 控制游戏手柄

[ 2006-05-16 08:53:14 | 作者: ccloveaa ]
字体大小: | |
用这个插件可以允许你在director中使用简单的几个函数来使用游戏手柄
这样就可以开发那种单机游戏了 函数很简单

global joystick

on beginSprite
  joystick = xtra("joystick").new()
  joystick.useJoy(1) -- 使用第一个手柄
end

on fixedWidthNumber(iNumber, iWidth) string
  sNumber = string(iNumber)

  repeat while length(sNumber) < iWidth
    sNumber = "0" & sNumber
  end repeat

  return sNumber
end

on exitFrame me
  -- 显示按下的按扭
  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

  pointX = joystick.xPos() / 512.0
  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

点击下载

[最后修改由 ccloveaa, 于 2006-07-25 10:52:22]
评论Feed 评论Feed: http://www.ccloveaa.com/blog/feed.asp?q=comment&id=162
Gunner!Lingo,Flash action script,max plug-in.
Contact Way:QQ:58920142 MSN:ccloveaa@sina.com
李连杰->壹基金->民间后援团!

这篇日志没有评论.

发表评论
表情图标
[smile] [confused] [cool] [cry]
[eek] [angry] [wink] [sweat]
[lol] [stun] [razz] [redface]
[rolleyes] [sad] [yes] [no]
[heart] [star] [music] [idea]
UBB代码
转换链接
表情图标
悄悄话
用户名(*):   密码:   注册?
验证码 * 请输入验证码