[Flash 15+]
April 2015
BlankTemplate – Action Binder (first draft)
The actionBinder handle Keyboard, GameInput, and the AirGamepad (that transform any Android device into a remote gamepad).
Notes for AirGamepad :
– The swc can be found here in the AIR Sdk ( frameworks\libs\air\gamepad.swc )
– Strangely with android Adobe Air 17 I am not able to launch it, but you can DL the version 16 from the archive
– In Air 18, the gamepad is back :)
Example skin, that mimic the good old Nes game controller :)
Setp 1)
On AIRGamepadEvent.CONNECT event I replace the default image
//trace("createImageAndShowConfig request !"); // generate an image on the device var dim:Point = new Point(airGamePadRef.width, airGamePadRef.height); var tf:TextField = new TextField(); tf.defaultTextFormat = new TextFormat("Arial", 48, 0xFFFFFF, true, null, null, null, null, TextFormatAlign.CENTER); tf.width = dim.x; tf.height = 200; tf.text = "Gamepad connected !"; var ba:ByteArray = new ByteArray(); var dat:BitmapData = new BitmapData(dim.x, dim.y, false, 0x0); dat.draw(tf, new Matrix(1, 0, 0, 1, 0, dim.y * 1 / 3)); dat.encode(dat.rect, new JPEGEncoderOptions(80), ba); dat.dispose(); airGamePadRef.drawImage(ba); _configPanel.show();
Setp 2) building the resolution free gamepad skin on the fly and send it to the device
protected function _createAndApplySkin():void { //trace("_createAndApplySkin request !"); // clean old skin if any _clearDisplayList(); // get android screen res var dim:Point = new Point(airGamePadRef.width, airGamePadRef.height); _SW = dim.x; _SH = dim.y; // drawing this.graphics.beginFill(0xD1D2CD); this.graphics.drawRect(0, 0, _SW, _SH); this.graphics.beginFill(0xDADBD5); this.graphics.drawRect(0, 0, _SW, int(_SH * (3 / 18))); this.graphics.endFill(); var tf:TextField = new TextField(); tf.defaultTextFormat = new TextFormat("Impact", _SH * (3 / 36), 0xCE0005, false, true); tf.autoSize = TextFieldAutoSize.LEFT; tf.text = "AIR Advantage "; tf.selectable = false; tf.x = 10; tf.y = 10; addChild(tf); var tfGameName:TextField = new TextField(); tfGameName.defaultTextFormat = new TextFormat("Impact", _SH * (1 / 36), 0x484d53); tfGameName.autoSize = TextFieldAutoSize.LEFT; tfGameName.text = Config.GAME_NAME; tfGameName.selectable = false; tfGameName.x = 10; tfGameName.y = int(_SH * (3 / 18) - tfGameName.textHeight); addChild(tfGameName); _params = new Bitmap(new Params()); _params.height = _params.width = _SH * (3 / 36); _params.x = _SW - 20 - _params.width; _params.y = 20; addChild(_params); _vPad = new VirtualPad(int(_SW * (6 / 18))); _vPad.x += (_configPanel.rightHanded) ? int(4 / 18 * _SW) : int(14 / 18 * _SW); _vPad.y += int(6 / 9 * _SH); addChild(_vPad); _vBtnB = new VirtualButton(int(_SW * (4 / 18))); _vBtnB.x += (_configPanel.rightHanded) ? int(10 / 18 * _SW) : int(3 / 18 * _SW); _vBtnB.y += int(6 / 9 * _SH); addChild(_vBtnB); _vBtnA = new VirtualButton(int(_SW * (4 / 18))); _vBtnA.x += (_configPanel.rightHanded) ? int(15 / 18 * _SW) : int(8 / 18 * _SW); _vBtnA.y += int(6 / 9 * _SH); addChild(_vBtnA); _startBtn = new VirtualRoundedButton(int(_SW * (3 / 18))); _startBtn.x += (_configPanel.rightHanded) ? int(10 / 18 * _SW) : int(3 / 18 * _SW); _startBtn.y += int(3 / 9 * _SH); addChild(_startBtn); _selectBtn = new VirtualRoundedButton(int(_SW * (3 / 18))); _selectBtn.x += (_configPanel.rightHanded) ? int(15 / 18 * _SW) : int(8 / 18 * _SW); _selectBtn.y += int(3 / 9 * _SH); addChild(_selectBtn); _applySkin(); } protected function _applySkin():void { //trace("_applySkin request !"); var ba:ByteArray = new ByteArray(); var dat:BitmapData = new BitmapData(_SW, _SH, false, 0xCC0000); dat.draw(this); dat.encode(dat.rect, new JPEGEncoderOptions(100), ba); dat.dispose(); // send the skin on the mobile device airGamePadRef.drawImage(ba); // -- Wand Listeners airGamePadRef.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin); airGamePadRef.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove); airGamePadRef.addEventListener(TouchEvent.TOUCH_END, onTouchEnd); // accelerometer if (_configPanel.accelerometer) { airGamePadRef.addEventListener(AccelerometerEvent.UPDATE, _onAccUpdate); }
VirtualPad, VirtualButton and VirtualRoundedButton are regular bitmapFilled Shapes
