配合Starling 的 [範例] (請以鍵盤WASD 和m, 操控) |
as3dpad 渲染部分參考SpriteSheetClip 的手法, 所以在stage3d 之上有效運作, 與Starling 等框架相容.
另外, 類別庫提供以鍵盤代替螢幕輸入(WASD 和m,), 給開發人員在電腦直接測試遊戲.
弧度(radians) 表示操控桿位置 |
以下是編寫的簡單步驟:
- 建立DPad 物件
var dPad:DPad = new DPad(); this.addChild(dPad);
- 接收X 軸與Y 軸回傳的數據
dPad.leftPad.addEventListener(DPadEvent.TOUCH_PRESS, touchPressHandler); dPad.leftPad.addEventListener(DPadEvent.TOUCH_RELEASE, touchReleaseHandler); private function touchPressHandler(event:DPadEvent):void{ var axisPad:AxisPad = event.target as AxisPad; trace("radians: " + axisPad.radians); trace("distance: " + axisPad.distance + "/" + axisPad.maxDistance); trace("press left: " + (axisPad.value & AxisPad.LEFT)); trace("press right: " + (axisPad.value & AxisPad.RIGHT)); trace("press up: " + (axisPad.value & AxisPad.UP)); trace("press down: " + (axisPad.value & AxisPad.DOWN)); } private function touchReleaseHandler(event:DPadEvent):void{ ... }
- 接收A 和B 按鈕回傳的數據
dPad.rightPad.addEventListener(DPadEvent.TOUCH_PRESS_A, touchPressAHandler); dPad.rightPad.addEventListener(DPadEvent.TOUCH_PRESS_B, touchPressBHandler); dPad.rightPad.addEventListener(DPadEvent.TOUCH_RELEASE_A, touchReleaseAHandler); dPad.rightPad.addEventListener(DPadEvent.TOUCH_RELEASE_B, touchReleaseBHandler); private function touchPressAHandler(event:DPadEvent):void{ var groupPad:GroupPad = event.target as GroupPad; trace("press A: " + (groupPad.value & GroupPad.A_BUTTON)); trace("press B: " + (groupPad.value & GroupPad.B_BUTTON)); } private function touchPressBHandler(event:DPadEvent):void{ ... } private function touchReleaseAHandler(event:DPadEvent):void{ ... } private function touchReleaseBHandler(event:DPadEvent):void{ ... }
類別庫提供以下範例參考:
- example01_basic - 基本用法 [demo]
- example02_custom_UI - 自定介面 [demo]
- example03_double_AxisPad - 雙操控桿 [demo]
- example04_touch9Grid - 螢幕九格觸控 [demo]
- example05_starling - 配合Starling [demo]
大家可以 [下載] 範例試試看.
沒有留言:
張貼留言