├── .gitignore
├── LICENSE
├── README.md
├── as3dpad
├── .actionScriptProperties
├── .flexLibProperties
├── .project
├── bin
│ └── as3dpad.swc
├── embed
│ └── dpad
│ │ ├── axisBase.png
│ │ ├── axisStick.png
│ │ └── axisStickPress.png
└── src
│ └── duckleg
│ └── dpad
│ ├── AxisPad.as
│ ├── BasePad.as
│ ├── DPad.as
│ ├── DPadEvent.as
│ ├── GroupButton.as
│ └── GroupPad.as
└── as3dpad_example
├── .actionScriptProperties
├── .project
├── embed
├── aeroplane.png
├── axisBase01.png
├── axisStick01.png
├── axisStickPress01.png
├── bullet.png
├── buttonStick01.png
├── buttonStick02.png
├── buttonStickPress01.png
├── buttonStickPress02.png
├── grass.png
├── icon_music.png
├── icon_pause.png
├── icon_setting.png
├── landscape.jpg
├── penguin.png
├── penguin_moving.png
├── penguin_moving.xml
├── penguin_waving.png
└── penguin_waving.xml
├── libs
├── as3dpad.swc
├── greensock.swc
└── starling.swc
└── src
├── as3dpad_example-app.xml
├── as3dpad_example.as
├── duckleg
└── starling
│ └── MyPenguin.as
├── example01_basic.as
├── example02_custom_UI.as
├── example03_double_AxisPad.as
├── example04_touch9Grid.as
├── example05_starling.as
└── net
└── hires
└── debug
├── Stats.as
└── Stats.hx
/.gitignore:
--------------------------------------------------------------------------------
1 | # Build and Release Folders
2 | bin-debug/
3 | bin-release/
4 |
5 | # Project property files
6 | .actionScriptProperties
7 | .flexProperties
8 | .settings/
9 | .project
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (C) 2012 Marco Wong, http://flash-adobe.blogspot.hk/
2 |
3 | Licence Agreement (The MIT License)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | as3dpad
2 | =======
3 | as3dpad is a virtual gamepad designed for Adobe AIR mobile. You can develop a iOS/Android game and receive user data from the touch screen. X and Y axis data will be represented to “UP”, “DOWN”, “LEFT”, “RIGHT” and a radians.
4 |
5 | 
6 | 
7 |
8 |
9 | ## Features
10 |
11 | - X and Y-axis
12 | - A, B, C and D Buttons
13 | - custom UI
14 | - key mapping for development on desktop (WASD + m,./)
15 | - available with stage3d (e.g.: Starling, Away3D, Alternativa3D...)
16 |
17 | ## What does work
18 |
19 |
20 | First of all, you'll create an instance of the DPad and add to the stage.
21 | ```as3
22 | var dPad:DPad = new DPad();
23 | this.addChild(dPad);
24 | ````
25 |
26 | Add a detection listener for AxisPad. You'll get values on X and Y-axis.
27 | ```as3
28 | dPad.leftPad.addEventListener(DPadEvent.TOUCH_PRESS, touchPressHandler);
29 | dPad.leftPad.addEventListener(DPadEvent.TOUCH_RELEASE, touchReleaseHandler);
30 |
31 | private function touchPressHandler(event:DPadEvent):void{
32 | var axisPad:AxisPad = event.target as AxisPad;
33 | trace("radians: " + axisPad.radians);
34 | trace("distance: " + axisPad.distance + "/" + axisPad.maxDistance);
35 | trace("press left: " + (axisPad.value & AxisPad.LEFT));
36 | trace("press right: " + (axisPad.value & AxisPad.RIGHT));
37 | trace("press up: " + (axisPad.value & AxisPad.UP));
38 | trace("press down: " + (axisPad.value & AxisPad.DOWN));
39 | }
40 | private function touchReleaseHandler(event:DPadEvent):void{
41 | ...
42 | }
43 | ````
44 |
45 | Add a detection listener for GroupPad. You'll get values on A and B buttons.
46 | ```as3
47 | dPad.rightPad.addEventListener(DPadEvent.TOUCH_PRESS_A, touchPressAHandler);
48 | dPad.rightPad.addEventListener(DPadEvent.TOUCH_PRESS_B, touchPressBHandler);
49 | dPad.rightPad.addEventListener(DPadEvent.TOUCH_RELEASE_A, touchReleaseAHandler);
50 | dPad.rightPad.addEventListener(DPadEvent.TOUCH_RELEASE_B, touchReleaseBHandler);
51 |
52 | private function touchPressAHandler(event:DPadEvent):void{
53 | var groupPad:GroupPad = event.target as GroupPad;
54 | trace("press A: " + (groupPad.value & GroupPad.A_BUTTON));
55 | trace("press B: " + (groupPad.value & GroupPad.B_BUTTON));
56 | }
57 | private function touchPressBHandler(event:DPadEvent):void{
58 | ...
59 | }
60 | private function touchReleaseAHandler(event:DPadEvent):void{
61 | ...
62 | }
63 | private function touchReleaseBHandler(event:DPadEvent):void{
64 | ...
65 | }
66 | ````
67 |
68 | ## Examples
69 |
70 | - example01_basic [demo](https://sites.google.com/site/ducklegflash/as3dpad/example01_basic)
71 | - example02_custom_UI [demo](https://sites.google.com/site/ducklegflash/as3dpad/example02_custom_ui)
72 | - example03_double_AxisPad [demo](https://sites.google.com/site/ducklegflash/as3dpad/example03_double_axispad)
73 | - example04_touch9Grid [demo](https://sites.google.com/site/ducklegflash/as3dpad/example04_touch9grid)
74 | - example05_starling [demo](https://sites.google.com/site/ducklegflash/as3dpad/example05_starling)
75 |
76 | [](https://sites.google.com/site/ducklegflash/as3dpad/example01_basic)
77 | [](https://sites.google.com/site/ducklegflash/as3dpad/example02_custom_ui)
78 | [](https://sites.google.com/site/ducklegflash/as3dpad/example03_double_axispad)
79 | [](https://sites.google.com/site/ducklegflash/as3dpad/example04_touch9grid)
80 | [](https://sites.google.com/site/ducklegflash/as3dpad/example05_starling)
81 |
82 | (Click the image to see some demos. Be patient, no preloader!)
83 |
84 | ## Download
85 |
86 | SWC Library - [as3dpad.swc](https://github.com/duckleg/as3dpad/tree/master/as3dpad/bin)
87 |
88 | ## License
89 |
90 | Copyright (C) 2012 Marco Wong, http://flash-adobe.blogspot.hk/
91 |
92 | Licence Agreement (The MIT License)
93 |
94 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
95 |
96 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
97 |
98 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/as3dpad/.actionScriptProperties:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/as3dpad/.flexLibProperties:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/as3dpad/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | as3dpad
4 |
5 |
6 |
7 |
8 |
9 | com.adobe.flexbuilder.project.flexbuilder
10 |
11 |
12 |
13 |
14 |
15 | com.adobe.flexbuilder.project.flexlibnature
16 | com.adobe.flexbuilder.project.actionscriptnature
17 |
18 |
19 |
--------------------------------------------------------------------------------
/as3dpad/bin/as3dpad.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad/bin/as3dpad.swc
--------------------------------------------------------------------------------
/as3dpad/embed/dpad/axisBase.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad/embed/dpad/axisBase.png
--------------------------------------------------------------------------------
/as3dpad/embed/dpad/axisStick.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad/embed/dpad/axisStick.png
--------------------------------------------------------------------------------
/as3dpad/embed/dpad/axisStickPress.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad/embed/dpad/axisStickPress.png
--------------------------------------------------------------------------------
/as3dpad/src/duckleg/dpad/AxisPad.as:
--------------------------------------------------------------------------------
1 | package duckleg.dpad
2 | {
3 | import flash.display.Bitmap;
4 | import flash.display.BitmapData;
5 | import flash.events.Event;
6 | import flash.events.KeyboardEvent;
7 | import flash.events.TouchEvent;
8 | import flash.geom.Point;
9 |
10 | public class AxisPad extends BasePad
11 | {
12 | [Embed(source="../embed/dpad/axisBase.png")]
13 | public static const DEFAULT_AXIS_BASE:Class;
14 |
15 | [Embed(source="../embed/dpad/axisStick.png")]
16 | public static const DEFAULT_AXIS_STICK:Class;
17 |
18 | [Embed(source="../embed/dpad/axisStickPress.png")]
19 | public static const DEFAULT_AXIS_STICK_PRESS:Class;
20 |
21 | // <----- const value
22 | public static const LEFT:int = 2;
23 | public static const RIGHT:int = 4;
24 | public static const UP:int = 8;
25 | public static const DOWN:int = 16;
26 |
27 | // <----- for speed up calculation
28 | private static const PI0:Number = Math.PI/8;
29 | private static const PI1:Number = PI0*3;
30 | private static const PI2:Number = PI0*5;
31 | private static const PI3:Number = PI0*7;
32 | private static const PI4:Number = -Math.PI/8;
33 | private static const PI5:Number = PI4*3;
34 | private static const PI6:Number = PI4*5;
35 | private static const PI7:Number = PI4*7;
36 | private static const PI_RIGHT:Number = 0;
37 | private static const PI_RIGHT_DOWN:Number = PI0*2;
38 | private static const PI_DOWN:Number = PI0*4;
39 | private static const PI_LEFT_DOWN:Number = PI0*6;
40 | private static const PI_LEFT:Number = Math.PI;
41 | private static const PI_LEFT_UP:Number = PI4*6;
42 | private static const PI_UP:Number = PI4*4;
43 | private static const PI_RIGHT_UP:Number = PI4*2;
44 |
45 | // <----- UI variable
46 | private var _stickBitmapData:BitmapData;
47 | private var _stickPressBitmapData:BitmapData;
48 | private var _base:Bitmap;
49 | private var _stick:Bitmap;
50 |
51 | // <----- const for a instance
52 | private var _buttonX:int;
53 | private var _buttonY:int;
54 | private var _buttonW:int;
55 | private var _maxDistance:int;
56 |
57 | // <----- status variable
58 | private var _touchPointID:int;
59 | private var _touch:Point;
60 | private var _distance:Number;
61 | private var _radians:Number;
62 | private var _value:int;
63 |
64 | // <----- keycode mapping
65 | private var _leftKeycode:int = 65;
66 | private var _rightKeycode:int = 68;
67 | private var _upKeycode:int = 87;
68 | private var _downKeycode:int = 83;
69 |
70 | // **************************************************** main
71 | public function AxisPad(valign:String="bottom", base:BitmapData=null, stick:BitmapData=null, stickPress:BitmapData=null){
72 | super(valign);
73 |
74 | // <----- adjust arguments
75 | if(base==null) base = (new DEFAULT_AXIS_BASE() as Bitmap).bitmapData;
76 | if(stick==null) stick = (new DEFAULT_AXIS_STICK() as Bitmap).bitmapData;
77 | if(stickPress==null) stickPress = (new DEFAULT_AXIS_STICK_PRESS() as Bitmap).bitmapData;
78 |
79 | // <----- cache variable
80 | _stickBitmapData = stick;
81 | _stickPressBitmapData = stickPress;
82 |
83 | // <----- create instance
84 | _base = new Bitmap(base);
85 | _stick = new Bitmap(_stickBitmapData);
86 |
87 | // <----- set property
88 | _base.x = -base.width/2;
89 | _base.y = -base.height/2;
90 | _stick.x = _buttonX = -int(_stickBitmapData.width/2);
91 | _stick.y = _buttonY = -int(_stickBitmapData.height/2);
92 | _maxDistance = int((Math.max(base.width, base.height) - Math.max(_stickBitmapData.width, _stickBitmapData.height))/2);
93 |
94 | // <----- add child
95 | this.addChild(_base);
96 | this.addChild(_stick);
97 | }
98 |
99 | // **************************************************** override public method
100 | override public function reset():void{
101 | _touchPointID = -1;
102 | _touch = new Point(0, 0);
103 | _distance = 0;
104 | _radians = 0;
105 | _stick.x = _buttonX;
106 | _stick.y = _buttonY;
107 | _value = 0;
108 | }
109 | override public function touchBegin(stageX:Number, stageY:Number, touchPointID:int):void{
110 | if(_base.hitTestPoint(stageX, stageY)){
111 | // <----- cache touch id
112 | _touchPointID = touchPointID;
113 |
114 | // <----- change UI
115 | _stick.bitmapData = _stickPressBitmapData;
116 |
117 | // <----- dispatch event
118 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_PRESS));
119 | }
120 | }
121 | override public function touchMove(stageX:Number, stageY:Number, touchPointID:int):void{
122 | if(_touchPointID==touchPointID){
123 | // <----- cache variable
124 | _touch = globalToLocal(new Point(stageX, stageY));
125 | _distance = Math.min(BasePad.getDistance(0, 0, _touch.x, _touch.y), _maxDistance);
126 | _radians = BasePad.getRadians(0, 0, _touch.x, _touch.y);
127 |
128 | // <----- set UI
129 | _stick.x = BasePad.getPolarX(0, _radians, _distance) + _buttonX;
130 | _stick.y = BasePad.getPolarY(0, _radians, _distance) + _buttonY;
131 |
132 | // <----- set value
133 | if(_radians>=0){
134 | if(_radiansPI4)
146 | _value = RIGHT;
147 | else if(_radians>PI5)
148 | _value = RIGHT | UP;
149 | else if(_radians>PI6)
150 | _value = UP;
151 | else if(_radians>PI7)
152 | _value = LEFT | UP;
153 | else
154 | _value = LEFT;
155 | }
156 | }
157 | }
158 | override public function touchEnd(stageX:Number, stageY:Number, touchPointID:int):void{
159 | if(_touchPointID==touchPointID){
160 | // <----- change UI
161 | _stick.bitmapData = _stickBitmapData;
162 |
163 | // <----- dispatch event
164 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_RELEASE));
165 |
166 | // <----- reset
167 | reset();
168 | }
169 | }
170 | override public function keyDown(keyCode:uint):void{
171 | var press:Boolean = false;
172 | var v:int = _value;
173 | switch(keyCode){
174 | case _leftKeycode:
175 | if(!(_value&LEFT)){
176 | _value |= LEFT;
177 | press = true;
178 | }
179 | break;
180 | case _rightKeycode:
181 | if(!(_value&RIGHT)){
182 | _value |= RIGHT;
183 | press = true;
184 | }
185 | break;
186 | case _upKeycode:
187 | if(!(_value&UP)){
188 | _value |= UP;
189 | press = true;
190 | }
191 | break;
192 | case _downKeycode:
193 | if(!(_value&DOWN)){
194 | _value |= DOWN;
195 | press = true;
196 | }
197 | break;
198 | }
199 |
200 | if(press){
201 | // <----- cache variable
202 | _distance = _maxDistance;
203 | _radians = findPI(_value);
204 |
205 | // <----- set UI
206 | _stick.x = BasePad.getPolarX(0, _radians, _distance) + _buttonX;
207 | _stick.y = BasePad.getPolarY(0, _radians, _distance) + _buttonY;
208 |
209 | if(v==0){
210 | // <----- change UI
211 | _stick.bitmapData = _stickPressBitmapData;
212 |
213 | // <----- dispatch event
214 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_PRESS));
215 | }
216 | }
217 | }
218 | override public function keyUp(keyCode:uint):void{
219 | var release:Boolean = false;
220 | switch(keyCode){
221 | case _leftKeycode:
222 | _value &= ~LEFT;
223 | release = true;
224 | break;
225 | case _rightKeycode:
226 | _value &= ~RIGHT;
227 | release = true;
228 | break;
229 | case _upKeycode:
230 | _value &= ~UP;
231 | release = true;
232 | break;
233 | case _downKeycode:
234 | _value &= ~DOWN;
235 | release = true;
236 | break;
237 | }
238 |
239 | if(release){
240 | // <----- cache variable
241 | _distance = _maxDistance;
242 | _radians = findPI(_value);
243 |
244 | // <----- set UI
245 | _stick.x = BasePad.getPolarX(0, _radians, _distance) + _buttonX;
246 | _stick.y = BasePad.getPolarY(0, _radians, _distance) + _buttonY;
247 |
248 | if(_value==0){
249 | // <----- change UI
250 | _stick.bitmapData = _stickBitmapData;
251 |
252 | // <----- dispatch event
253 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_RELEASE));
254 |
255 | // <----- reset
256 | reset();
257 | }
258 | }
259 | }
260 | override public function toString():String{
261 | return "{value:"+_value+", radians:"+_radians+", distance:"+_distance+", maxDistance:"+_maxDistance+"}";
262 | }
263 |
264 | // **************************************************** getter
265 | public function get touch():Point{
266 | return _touch;
267 | }
268 | public function get maxDistance():int{
269 | return _maxDistance;
270 | }
271 | public function get distance():Number{
272 | return _distance;
273 | }
274 | public function get radians():Number{
275 | return _radians;
276 | }
277 |
278 | // **************************************************** overrite getter
279 | override public function get value():int{
280 | return _value;
281 | }
282 |
283 | // **************************************************** setter
284 | public function set leftKeycode(value:int):void{
285 | _leftKeycode = value;
286 | }
287 | public function set rightKeycode(value:int):void{
288 | _rightKeycode = value;
289 | }
290 | public function set upKeycode(value:int):void{
291 | _upKeycode = value;
292 | }
293 | public function set downKeycode(value:int):void{
294 | _downKeycode = value;
295 | }
296 |
297 | // **************************************************** private method
298 | private function findPI(value:int):Number{
299 | switch(value){
300 | case 4:
301 | return PI_RIGHT;
302 | break;
303 | case 20:
304 | return PI_RIGHT_DOWN;
305 | break;
306 | case 16:
307 | return PI_DOWN;
308 | break;
309 | case 18:
310 | return PI_LEFT_DOWN;
311 | break;
312 | case 2:
313 | return PI_LEFT;
314 | break;
315 | case 10:
316 | return PI_LEFT_UP;
317 | break;
318 | case 8:
319 | return PI_UP;
320 | break;
321 | case 12:
322 | return PI_RIGHT_UP;
323 | break;
324 | }
325 | return 0;
326 | }
327 | }
328 | }
--------------------------------------------------------------------------------
/as3dpad/src/duckleg/dpad/BasePad.as:
--------------------------------------------------------------------------------
1 | package duckleg.dpad
2 | {
3 | import flash.display.Sprite;
4 |
5 | public class BasePad extends Sprite
6 | {
7 | public static const VALIGN_TOP:String = "top";
8 | public static const VALIGN_BOTTOM:String = "bottom";
9 |
10 | protected var _valign:String;
11 |
12 | // **************************************************** main
13 | public function BasePad(valign:String="bottom"){
14 | _valign = valign;
15 | }
16 |
17 | // **************************************************** getter
18 | public function get valign():String{
19 | return _valign;
20 | }
21 | public function get value():int{
22 | return -1;
23 | }
24 |
25 | // **************************************************** public method for overriding
26 | public function reset():void{}
27 | public function touchBegin(stageX:Number, stageY:Number, touchPointID:int):void{}
28 | public function touchMove(stageX:Number, stageY:Number, touchPointID:int):void{}
29 | public function touchEnd(stageX:Number, stageY:Number, touchPointID:int):void{}
30 | public function keyDown(keyCode:uint):void{}
31 | public function keyUp(keyCode:uint):void{}
32 |
33 | // **************************************************** static public method
34 | public static function getRadians(x1:Number, y1:Number, x2:Number, y2:Number):Number{
35 | return Math.atan2(y2 - y1, x2 - x1);
36 | }
37 | public static function getDistance(x1:Number, y1:Number, x2:Number, y2:Number):Number{
38 | return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
39 | }
40 | public static function getPolarX(x:Number, radians:Number, distance:Number):Number{
41 | return x + Math.round(distance*Math.cos(radians));
42 | }
43 | public static function getPolarY(y:Number, radians:Number, distance:Number):Number{
44 | return y + Math.round(distance*Math.sin(radians));
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/as3dpad/src/duckleg/dpad/DPad.as:
--------------------------------------------------------------------------------
1 | package duckleg.dpad
2 | {
3 | import flash.display.Sprite;
4 | import flash.events.Event;
5 | import flash.events.KeyboardEvent;
6 | import flash.events.TouchEvent;
7 | import flash.geom.Point;
8 | import flash.geom.Rectangle;
9 | import flash.ui.Multitouch;
10 | import flash.ui.MultitouchInputMode;
11 |
12 | public class DPad extends Sprite
13 | {
14 | public static const DEFAULT_PADDING:int = 130;
15 |
16 | public static const TOUCH_LEFT_TOP:int = 2;
17 | public static const TOUCH_TOP:int = 4;
18 | public static const TOUCH_RIGHT_TOP:int = 8;
19 | public static const TOUCH_LEFT_MIDDLE:int = 16;
20 | public static const TOUCH_MIDDLE:int = 32;
21 | public static const TOUCH_RIGHT_MIDDLE:int = 64;
22 | public static const TOUCH_LEFT_BOTTOM:int = 128;
23 | public static const TOUCH_BOTTOM:int = 256;
24 | public static const TOUCH_RIGHT_BOTTOM:int = 512;
25 |
26 | // <----- UI variable
27 | private var _lPad:BasePad;
28 | private var _rPad:BasePad;
29 | private var _padding:int = DEFAULT_PADDING;
30 |
31 | // <----- touch9Grid variable
32 | private var _touch9Grid:Boolean;
33 | private var _touch9Rects:Vector.;
34 | private var _touch9Value:int;
35 | private var _touch9Ids:Vector.;
36 | private var _touch9Keycodes:Vector.;
37 | private var _touch:Point;
38 |
39 | // <----- keycode mapping
40 | private var _leftTopKeycode:int = 103;
41 | private var _topKeycode:int = 104;
42 | private var _rightTopKeycode:int = 105;
43 | private var _leftMiddleKeycode:int = 100;
44 | private var _middleKeycode:int = 101;
45 | private var _rightMiddleKeycode:int = 102;
46 | private var _leftBottomKeycode:int = 97;
47 | private var _bottomKeycode:int = 98;
48 | private var _rightBottomKeycode:int = 99;
49 |
50 |
51 | // **************************************************** main
52 | public function DPad(leftPad:BasePad=null, rightPad:BasePad=null, touch9Grid:Boolean=false){
53 | // <----- adjust arguments
54 | if(leftPad==null) leftPad = new AxisPad();
55 | if(rightPad==null) rightPad = new GroupPad();
56 |
57 | // <----- cache variable
58 | _lPad = leftPad;
59 | _rPad = rightPad;
60 | _touch9Grid = touch9Grid;
61 |
62 | // <----- create mapping for touch9Grid
63 | if(_touch9Grid){
64 | _touch9Ids = new Vector.;
65 | _touch9Ids.push(TOUCH_LEFT_TOP);
66 | _touch9Ids.push(TOUCH_TOP);
67 | _touch9Ids.push(TOUCH_RIGHT_TOP);
68 | _touch9Ids.push(TOUCH_LEFT_MIDDLE);
69 | _touch9Ids.push(TOUCH_MIDDLE);
70 | _touch9Ids.push(TOUCH_RIGHT_MIDDLE);
71 | _touch9Ids.push(TOUCH_LEFT_BOTTOM);
72 | _touch9Ids.push(TOUCH_BOTTOM);
73 | _touch9Ids.push(TOUCH_RIGHT_BOTTOM);
74 | _touch9Keycodes = new Vector.;
75 | _touch9Keycodes.push(_leftTopKeycode);
76 | _touch9Keycodes.push(_topKeycode);
77 | _touch9Keycodes.push(_rightTopKeycode);
78 | _touch9Keycodes.push(_leftMiddleKeycode);
79 | _touch9Keycodes.push(_middleKeycode);
80 | _touch9Keycodes.push(_rightMiddleKeycode);
81 | _touch9Keycodes.push(_leftBottomKeycode);
82 | _touch9Keycodes.push(_bottomKeycode);
83 | _touch9Keycodes.push(_rightBottomKeycode);
84 | }
85 |
86 | // <----- set property
87 | this.visible = false;
88 |
89 | // <----- add listener - Sprite
90 | this.addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
91 | this.addEventListener(Event.REMOVED_FROM_STAGE, removedFromStageHandler);
92 |
93 | // <----- add child
94 | if(_lPad!=null) this.addChild(_lPad);
95 | if(_rPad!=null) this.addChild(_rPad);
96 | }
97 |
98 | // **************************************************** event - Sprite
99 | private function addedToStageHandler(event:Event):void{
100 | // <----- set input mode
101 | Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
102 |
103 | // <----- add listener - Stage
104 | this.stage.addEventListener(Event.RESIZE, resizeHandler);
105 |
106 | // <----- add listener - TouchEvent
107 | this.stage.addEventListener(TouchEvent.TOUCH_BEGIN, touchBeginHandler);
108 | this.stage.addEventListener(TouchEvent.TOUCH_MOVE, touchMoveHandler);
109 | this.stage.addEventListener(TouchEvent.TOUCH_END, touchEndHandler);
110 |
111 | // <----- add listener - KeyboardEvent
112 | this.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
113 | this.stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
114 |
115 | // <----- add listener for touch9Grid
116 | if(_touch9Grid){
117 | this.stage.addEventListener(TouchEvent.TOUCH_BEGIN, touchBeginTouch9GridHandler);
118 | this.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownTouch9GridHandler);
119 | }
120 |
121 | // <----- set UI position
122 | resizeHandler(null);
123 |
124 | // <----- reset
125 | _lPad.reset();
126 | _rPad.reset();
127 | _touch9Value = 0;
128 | }
129 | private function removedFromStageHandler(event:Event):void{
130 | // <----- set input mode
131 | Multitouch.inputMode = MultitouchInputMode.NONE;
132 |
133 | // <----- add listener - Stage
134 | this.stage.removeEventListener(Event.RESIZE, resizeHandler);
135 |
136 | // <----- remove listener - TouchEvent
137 | this.stage.removeEventListener(TouchEvent.TOUCH_BEGIN, touchBeginHandler);
138 | this.stage.removeEventListener(TouchEvent.TOUCH_MOVE, touchMoveHandler);
139 | this.stage.removeEventListener(TouchEvent.TOUCH_END, touchEndHandler);
140 |
141 | // <----- remove listener - KeyboardEvent
142 | this.stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
143 | this.stage.removeEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
144 |
145 | // <----- add listener for touch9Grid
146 | if(_touch9Grid){
147 | this.stage.removeEventListener(TouchEvent.TOUCH_BEGIN, touchBeginTouch9GridHandler);
148 | this.stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownTouch9GridHandler);
149 | }
150 |
151 | // <----- reset
152 | _lPad.reset();
153 | _rPad.reset();
154 | }
155 | private function resizeHandler(event:Event):void{
156 | var w:int = this.stage.stageWidth;
157 | var h:int = this.stage.stageHeight;
158 | _lPad.x = _padding;
159 | _lPad.y = _lPad.valign==BasePad.VALIGN_BOTTOM?h - _padding:_padding;
160 | _rPad.x = w - _padding;
161 | _rPad.y = _rPad.valign==BasePad.VALIGN_BOTTOM?h - _padding:_padding;
162 | this.visible = true;
163 |
164 | // <----- touch 9 grid hit area
165 | if(_touch9Grid){
166 | var w3:Number = w/3;
167 | var w32:Number = w3*2;
168 | var h3:Number = h/3;
169 | var h32:Number = h3*2;
170 | _touch9Rects = new Vector.;
171 | _touch9Rects.push(new Rectangle(0, 0, w3, h3));
172 | _touch9Rects.push(new Rectangle(w3, 0, w3, h3));
173 | _touch9Rects.push(new Rectangle(w32, 0, w3, h3));
174 | _touch9Rects.push(new Rectangle(0, h3, w3, h3));
175 | _touch9Rects.push(new Rectangle(w3, h3, w3, h3));
176 | _touch9Rects.push(new Rectangle(w32, h3, w3, h3));
177 | _touch9Rects.push(new Rectangle(0, h32, w3, h3));
178 | _touch9Rects.push(new Rectangle(w3, h32, w3, h3));
179 | _touch9Rects.push(new Rectangle(w32, h32, w3, h3));
180 | }
181 | }
182 | override public function toString():String{
183 | return "{leftPad:"+_lPad+", rightPad:"+_rPad+"}";
184 | }
185 |
186 | // **************************************************** event - TouchEvent
187 | private function touchBeginHandler(event:TouchEvent):void{
188 | _lPad.touchBegin(event.stageX, event.stageY, event.touchPointID);
189 | _rPad.touchBegin(event.stageX, event.stageY, event.touchPointID);
190 | }
191 | private function touchMoveHandler(event:TouchEvent):void{
192 | _lPad.touchMove(event.stageX, event.stageY, event.touchPointID);
193 | _rPad.touchMove(event.stageX, event.stageY, event.touchPointID);
194 | }
195 | private function touchEndHandler(event:TouchEvent):void{
196 | _lPad.touchEnd(event.stageX, event.stageY, event.touchPointID);
197 | _rPad.touchEnd(event.stageX, event.stageY, event.touchPointID);
198 | }
199 | private function touchBeginTouch9GridHandler(event:TouchEvent):void{
200 | // <----- find hit area, if touch9Grid is enabled
201 | _touch9Value = 0;
202 | _touch = new Point(event.stageX, event.stageY);
203 | for(var i:int=0; i<_touch9Rects.length; i++)
204 | if(_touch9Rects[i].containsPoint(_touch)){
205 | // <----- cache variable
206 | _touch9Value |= _touch9Ids[i];
207 |
208 | // <----- dispatch event
209 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_PRESS_9_GRID));
210 |
211 | // <----- break this method
212 | return;
213 | }
214 | }
215 |
216 | // **************************************************** event - KeyboardEvent
217 | private function keyDownHandler(event:KeyboardEvent):void{
218 | _lPad.keyDown(event.keyCode);
219 | _rPad.keyDown(event.keyCode);
220 | }
221 | private function keyUpHandler(event:KeyboardEvent):void{
222 | _lPad.keyUp(event.keyCode);
223 | _rPad.keyUp(event.keyCode);
224 | }
225 | private function keyDownTouch9GridHandler(event:KeyboardEvent):void{
226 | // <----- find hit area, if touch9Grid is enabled
227 | _touch9Value = 0;
228 | for(var i:int=0; i<_touch9Keycodes.length; i++)
229 | if(event.keyCode==_touch9Keycodes[i]){
230 | // <----- cache variable
231 | _touch9Value |= _touch9Ids[i];
232 | _touch = new Point(_touch9Rects[i].x+_touch9Rects[i].width/2, _touch9Rects[i].y+_touch9Rects[i].height/2);
233 |
234 | // <----- dispatch event
235 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_PRESS_9_GRID));
236 |
237 | // <----- break this method
238 | return;
239 | }
240 | }
241 |
242 | // **************************************************** setter
243 | public function set padding(value:int):void{
244 | _padding = value;
245 | resizeHandler(null);
246 | }
247 |
248 | // **************************************************** getter
249 | public function get padding():int{
250 | return _padding;
251 | }
252 | public function get leftPad():BasePad{
253 | return _lPad;
254 | }
255 | public function get rightPad():BasePad{
256 | return _rPad;
257 | }
258 | public function get touch9Value():int{
259 | return _touch9Value;
260 | }
261 | public function get touch():Point{
262 | return _touch;
263 | }
264 | }
265 | }
--------------------------------------------------------------------------------
/as3dpad/src/duckleg/dpad/DPadEvent.as:
--------------------------------------------------------------------------------
1 | package duckleg.dpad
2 | {
3 | import flash.events.Event;
4 |
5 | public class DPadEvent extends Event
6 | {
7 | public static const TOUCH_PRESS:String = "touch_press";
8 | public static const TOUCH_RELEASE:String = "touch_release";
9 |
10 | public static const TOUCH_PRESS_A:String = "touch_press_a";
11 | public static const TOUCH_RELEASE_A:String = "touch_release_a";
12 | public static const TOUCH_PRESS_B:String = "touch_press_b";
13 | public static const TOUCH_RELEASE_B:String = "touch_release_b";
14 | public static const TOUCH_PRESS_C:String = "touch_press_c";
15 | public static const TOUCH_RELEASE_C:String = "touch_release_c";
16 | public static const TOUCH_PRESS_D:String = "touch_press_d";
17 | public static const TOUCH_RELEASE_D:String = "touch_release_d";
18 |
19 | public static const TOUCH_PRESS_9_GRID:String = "touch_press_9_grid";
20 |
21 | public function DPadEvent(type:String, bubbles:Boolean=false, cancelable:Boolean = false){
22 | super(type, bubbles, cancelable);
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/as3dpad/src/duckleg/dpad/GroupButton.as:
--------------------------------------------------------------------------------
1 | package duckleg.dpad
2 | {
3 | import flash.display.Bitmap;
4 | import flash.display.BitmapData;
5 |
6 | public class GroupButton extends Bitmap
7 | {
8 | [Embed(source="../embed/dpad/axisStick.png")]
9 | public static const DEFAULT_BUTTON:Class;
10 |
11 | [Embed(source="../embed/dpad/axisStickPress.png")]
12 | public static const DEFAULT_BUTTON_PRESS:Class;
13 |
14 | // <----- status variable
15 | private var _id:int;
16 | private var _touchPointID:int;
17 |
18 | // <----- UI variable
19 | private var _buttonBitmapData:BitmapData;
20 | private var _buttonPressBitmapData:BitmapData;
21 |
22 | // **************************************************** main
23 | public function GroupButton(id:int, button:BitmapData=null, buttonPress:BitmapData=null){
24 | // <----- adjust arguments
25 | if(button==null) button = (new DEFAULT_BUTTON() as Bitmap).bitmapData;
26 | if(buttonPress==null) buttonPress = (new DEFAULT_BUTTON_PRESS() as Bitmap).bitmapData;
27 |
28 | // <----- cache variable
29 | _id = id;
30 | _buttonBitmapData = button;
31 | _buttonPressBitmapData = buttonPress;
32 |
33 | // <----- set UI
34 | this.bitmapData = button;
35 | }
36 |
37 | // **************************************************** override public method
38 | override public function toString():String{
39 | return "{id:"+_id+", pressed:"+(_touchPointID>=0)+"}";
40 | }
41 |
42 | // **************************************************** getter
43 | public function get id():int{
44 | return _id;
45 | }
46 | public function get touchPointID():int{
47 | return _touchPointID;
48 | }
49 |
50 | // **************************************************** setter
51 | public function set touchPointID(value:int):void{
52 | _touchPointID = value;
53 |
54 | // <----- change UI
55 | if(value>=0)
56 | this.bitmapData = _buttonPressBitmapData;
57 | else
58 | this.bitmapData = _buttonBitmapData;
59 | }
60 | }
61 | }
--------------------------------------------------------------------------------
/as3dpad/src/duckleg/dpad/GroupPad.as:
--------------------------------------------------------------------------------
1 | package duckleg.dpad
2 | {
3 | import flash.events.Event;
4 | import flash.events.KeyboardEvent;
5 | import flash.events.TouchEvent;
6 |
7 | public class GroupPad extends BasePad
8 | {
9 | private static const DEFAULT_PADDING:int = 40;
10 |
11 | // <----- const value
12 | public static const A_BUTTON:int = 2;
13 | public static const B_BUTTON:int = 4;
14 | public static const C_BUTTON:int = 16;
15 | public static const D_BUTTON:int = 32;
16 |
17 | private var _buttons:Vector.;
18 | private var _value:int;
19 |
20 | // <----- keycode mapping
21 | private var _aKeycode:int = 77;
22 | private var _bKeycode:int = 188;
23 | private var _cKeycode:int = 190;
24 | private var _dKeycode:int = 191;
25 |
26 | // **************************************************** main
27 | public function GroupPad(valign:String="bottom", buttons:Vector.=null, defaultPosition:Boolean=true){
28 | super(valign);
29 |
30 | // <----- adjust arguments
31 | if(buttons==null || buttons.length==0){
32 | buttons = new Vector.;
33 | buttons.push(new GroupButton(A_BUTTON));
34 | buttons.push(new GroupButton(B_BUTTON));
35 | }
36 |
37 | // <----- cache variable
38 | _buttons = buttons;
39 |
40 | // <----- set default position
41 | if(defaultPosition){
42 | switch(_buttons.length){
43 | case 1:
44 | _buttons[0].x = -_buttons[0].width/2;
45 | _buttons[0].y = -_buttons[0].height/2;
46 | break;
47 | case 2:
48 | _buttons[0].x = -_buttons[0].width - DEFAULT_PADDING;
49 | _buttons[0].y = 0;
50 | _buttons[1].x = 0;
51 | _buttons[1].y = -_buttons[1].height;
52 | break;
53 | case 3:
54 | _buttons[0].x = -_buttons[0].width - DEFAULT_PADDING;
55 | _buttons[0].y = 0;
56 | _buttons[1].x = DEFAULT_PADDING;
57 | _buttons[1].y = 0;
58 | _buttons[2].x = -_buttons[2].width/2;
59 | _buttons[2].y = -_buttons[2].height - DEFAULT_PADDING;
60 | break;
61 | case 4:
62 | _buttons[0].x = -_buttons[0].width - DEFAULT_PADDING;
63 | _buttons[0].y = -_buttons[0].height/2;
64 | _buttons[1].x = DEFAULT_PADDING;
65 | _buttons[1].y = -_buttons[1].height/2;
66 | _buttons[2].x = -_buttons[2].width/2;
67 | _buttons[2].y = -_buttons[2].height - _buttons[0].height/2;
68 | _buttons[3].x = -_buttons[3].width/2;
69 | _buttons[3].y = _buttons[0].height/2;
70 | break;
71 | }
72 | }
73 |
74 | // <----- add child
75 | for(var i:int=0; i<_buttons.length; i++)
76 | this.addChild(_buttons[i]);
77 | }
78 |
79 | // **************************************************** override public method
80 | override public function reset():void{
81 | for(var i:int=0; i<_buttons.length; i++)
82 | _buttons[i].touchPointID = -1;
83 | _value = 0;
84 | }
85 | override public function touchBegin(stageX:Number, stageY:Number, touchPointID:int):void{
86 | for(var i:int=0; i<_buttons.length; i++)
87 | if(_buttons[i].hitTestPoint(stageX, stageY)){
88 | // <----- cache variable
89 | _buttons[i].touchPointID = touchPointID;
90 | _value |= _buttons[i].id;
91 |
92 | // <----- dispatch event
93 | switch(_buttons[i].id){
94 | case A_BUTTON:
95 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_PRESS_A));
96 | break;
97 | case B_BUTTON:
98 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_PRESS_B));
99 | break;
100 | case C_BUTTON:
101 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_PRESS_C));
102 | break;
103 | case D_BUTTON:
104 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_PRESS_D));
105 | break;
106 | }
107 |
108 | // <----- break this looping
109 | return;
110 | }
111 | }
112 | override public function touchEnd(stageX:Number, stageY:Number, touchPointID:int):void{
113 | for(var i:int=0; i<_buttons.length; i++)
114 | if(_buttons[i].touchPointID==touchPointID){
115 | // <----- reset variable
116 | _buttons[i].touchPointID = -1;
117 | _value &= ~_buttons[i].id;
118 |
119 | // <----- dispatch event
120 | switch(_buttons[i].id){
121 | case A_BUTTON:
122 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_RELEASE_A));
123 | break;
124 | case B_BUTTON:
125 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_RELEASE_B));
126 | break;
127 | case C_BUTTON:
128 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_RELEASE_C));
129 | break;
130 | case D_BUTTON:
131 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_RELEASE_D));
132 | break;
133 | }
134 |
135 | // <----- break this looping
136 | return;
137 | }
138 | }
139 | override public function keyDown(keyCode:uint):void{
140 | var button:GroupButton;
141 | switch(keyCode){
142 | case _aKeycode:
143 | if(!(_value&A_BUTTON)){
144 | // <----- set variable
145 | button = findGroupButton(A_BUTTON);
146 | _value |= A_BUTTON;
147 |
148 | // <----- change UI
149 | if(button!=null)
150 | button.touchPointID = 999;
151 |
152 | // <----- dispatch event
153 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_PRESS_A));
154 | }
155 | break;
156 | case _bKeycode:
157 | if(!(_value&B_BUTTON)){
158 | // <----- set variable
159 | button = findGroupButton(B_BUTTON);
160 | _value |= B_BUTTON;
161 |
162 | // <----- change UI
163 | if(button!=null)
164 | button.touchPointID = 999;
165 |
166 | // <----- dispatch event
167 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_PRESS_B));
168 | }
169 | break;
170 | case _cKeycode:
171 | if(!(_value&C_BUTTON)){
172 | // <----- set variable
173 | button = findGroupButton(C_BUTTON);
174 | _value |= C_BUTTON;
175 |
176 | // <----- change UI
177 | if(button!=null)
178 | button.touchPointID = 999;
179 |
180 | // <----- dispatch event
181 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_PRESS_C));
182 | }
183 | break;
184 | case _dKeycode:
185 | if(!(_value&D_BUTTON)){
186 | // <----- set variable
187 | button = findGroupButton(D_BUTTON);
188 | _value |= D_BUTTON;
189 |
190 | // <----- change UI
191 | if(button!=null)
192 | button.touchPointID = 999;
193 |
194 | // <----- dispatch event
195 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_PRESS_D));
196 | }
197 | break;
198 | }
199 | }
200 | override public function keyUp(keyCode:uint):void{
201 | var button:GroupButton;
202 | switch(keyCode){
203 | case _aKeycode:
204 | if(_value&A_BUTTON){
205 | // <----- set variable
206 | button = findGroupButton(A_BUTTON);
207 | _value &= ~A_BUTTON;
208 |
209 | // <----- change UI
210 | if(button!=null)
211 | button.touchPointID = -1;
212 |
213 | // <----- dispatch event
214 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_RELEASE_A));
215 | }
216 | break;
217 | case _bKeycode:
218 | if(_value&B_BUTTON){
219 | // <----- set variable
220 | button = findGroupButton(B_BUTTON);
221 | _value &= ~B_BUTTON;
222 |
223 | // <----- change UI
224 | if(button!=null)
225 | button.touchPointID = -1;
226 |
227 | // <----- dispatch event
228 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_RELEASE_B));
229 | }
230 | break;
231 | case _cKeycode:
232 | if(_value&C_BUTTON){
233 | // <----- set variable
234 | button = findGroupButton(C_BUTTON);
235 | _value &= ~C_BUTTON;
236 |
237 | // <----- change UI
238 | if(button!=null)
239 | button.touchPointID = -1;
240 |
241 | // <----- dispatch event
242 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_RELEASE_C));
243 | }
244 | break;
245 | case _dKeycode:
246 | if(_value&D_BUTTON){
247 | // <----- set variable
248 | button = findGroupButton(D_BUTTON);
249 | _value &= ~D_BUTTON;
250 |
251 | // <----- change UI
252 | if(button!=null)
253 | button.touchPointID = -1;
254 |
255 | // <----- dispatch event
256 | this.dispatchEvent(new DPadEvent(DPadEvent.TOUCH_RELEASE_D));
257 | }
258 | break;
259 | }
260 | }
261 | override public function toString():String{
262 | return "{value:"+_value+", buttons:["+_buttons+"]}";
263 | }
264 |
265 | // **************************************************** setter
266 | public function set aKeycode(value:int):void{
267 | _aKeycode = value;
268 | }
269 | public function set bKeycode(value:int):void{
270 | _bKeycode = value;
271 | }
272 | public function set cKeycode(value:int):void{
273 | _cKeycode = value;
274 | }
275 | public function set dKeycode(value:int):void{
276 | _dKeycode = value;
277 | }
278 |
279 | // **************************************************** getter
280 | public function get buttons():Vector.{
281 | return _buttons;
282 | }
283 |
284 | // **************************************************** overrite getter
285 | override public function get value():int{
286 | return _value;
287 | }
288 |
289 | // **************************************************** private method
290 | private function findGroupButton(id:int):GroupButton{
291 | for(var i:int=0; i<_buttons.length; i++)
292 | if(_buttons[i].id==id)
293 | return _buttons[i];
294 | return null;
295 | }
296 | }
297 | }
--------------------------------------------------------------------------------
/as3dpad_example/.actionScriptProperties:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------
/as3dpad_example/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | as3dpad_example
4 |
5 |
6 |
7 |
8 |
9 | com.adobe.flexbuilder.project.flexbuilder
10 |
11 |
12 |
13 |
14 | com.adobe.flexbuilder.project.apollobuilder
15 |
16 |
17 |
18 |
19 |
20 | com.adobe.flexide.project.multiplatform.multiplatformasnature
21 | com.adobe.flexide.project.multiplatform.multiplatformnature
22 | com.adobe.flexbuilder.project.apollonature
23 | com.adobe.flexbuilder.project.actionscriptnature
24 |
25 |
26 |
--------------------------------------------------------------------------------
/as3dpad_example/embed/aeroplane.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/aeroplane.png
--------------------------------------------------------------------------------
/as3dpad_example/embed/axisBase01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/axisBase01.png
--------------------------------------------------------------------------------
/as3dpad_example/embed/axisStick01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/axisStick01.png
--------------------------------------------------------------------------------
/as3dpad_example/embed/axisStickPress01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/axisStickPress01.png
--------------------------------------------------------------------------------
/as3dpad_example/embed/bullet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/bullet.png
--------------------------------------------------------------------------------
/as3dpad_example/embed/buttonStick01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/buttonStick01.png
--------------------------------------------------------------------------------
/as3dpad_example/embed/buttonStick02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/buttonStick02.png
--------------------------------------------------------------------------------
/as3dpad_example/embed/buttonStickPress01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/buttonStickPress01.png
--------------------------------------------------------------------------------
/as3dpad_example/embed/buttonStickPress02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/buttonStickPress02.png
--------------------------------------------------------------------------------
/as3dpad_example/embed/grass.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/grass.png
--------------------------------------------------------------------------------
/as3dpad_example/embed/icon_music.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/icon_music.png
--------------------------------------------------------------------------------
/as3dpad_example/embed/icon_pause.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/icon_pause.png
--------------------------------------------------------------------------------
/as3dpad_example/embed/icon_setting.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/icon_setting.png
--------------------------------------------------------------------------------
/as3dpad_example/embed/landscape.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/landscape.jpg
--------------------------------------------------------------------------------
/as3dpad_example/embed/penguin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/penguin.png
--------------------------------------------------------------------------------
/as3dpad_example/embed/penguin_moving.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/penguin_moving.png
--------------------------------------------------------------------------------
/as3dpad_example/embed/penguin_moving.xml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/penguin_moving.xml
--------------------------------------------------------------------------------
/as3dpad_example/embed/penguin_waving.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/penguin_waving.png
--------------------------------------------------------------------------------
/as3dpad_example/embed/penguin_waving.xml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/embed/penguin_waving.xml
--------------------------------------------------------------------------------
/as3dpad_example/libs/as3dpad.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/libs/as3dpad.swc
--------------------------------------------------------------------------------
/as3dpad_example/libs/greensock.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/libs/greensock.swc
--------------------------------------------------------------------------------
/as3dpad_example/libs/starling.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duckleg/as3dpad/f3064294df802f3c17a9db663b1b3a6b2f0ec100/as3dpad_example/libs/starling.swc
--------------------------------------------------------------------------------
/as3dpad_example/src/as3dpad_example-app.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
16 |
18 | com.gamevil.zenonia2
19 |
20 |
21 | as3dpad_example
22 |
23 |
25 | as3dpad_example
26 |
27 |
30 | 0.0.0
31 |
32 |
33 |
34 |
35 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | [This value will be overwritten by Flash Builder in the output app.xml]
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 | landscape
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 | direct
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 | true
113 | true
114 | true
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
136 |
147 |
148 |
151 |
152 |
153 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
202 |
203 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
244 |
245 |
247 |
248 |
249 |
250 |
251 |
253 |
254 |
255 |
256 |
257 |
259 |
260 |
261 |
262 |
263 | ]]>
264 |
265 |
266 | UIDeviceFamily
268 |
269 | 1
270 | 2
271 |
272 | ]]>
273 | high
274 |
275 |
276 |
--------------------------------------------------------------------------------
/as3dpad_example/src/as3dpad_example.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | [SWF(frameRate="60", backgroundColor="#FFFFFF")]
4 | //public class as3dpad_example extends example01_basic
5 | //public class as3dpad_example extends example02_custom_UI
6 | //public class as3dpad_example extends example03_double_AxisPad
7 | //public class as3dpad_example extends example04_touch9Grid
8 | public class as3dpad_example extends example05_starling
9 | {
10 | public function as3dpad_example()
11 | {
12 | super();
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/as3dpad_example/src/duckleg/starling/MyPenguin.as:
--------------------------------------------------------------------------------
1 | package duckleg.starling
2 | {
3 | import com.greensock.TweenLite;
4 | import com.greensock.easing.*;
5 |
6 | import duckleg.dpad.AxisPad;
7 | import duckleg.dpad.DPad;
8 | import duckleg.dpad.GroupPad;
9 |
10 | import net.hires.debug.Stats;
11 |
12 | import starling.core.Starling;
13 | import starling.display.Image;
14 | import starling.display.MovieClip;
15 | import starling.display.Sprite;
16 | import starling.events.Event;
17 | import starling.textures.Texture;
18 | import starling.textures.TextureAtlas;
19 |
20 | public class MyPenguin extends Sprite
21 | {
22 | [Embed(source="../embed/landscape.jpg")]
23 | private var LandscapeJPG:Class;
24 | [Embed(source="../embed/grass.png")]
25 | private var GrassPNG:Class;
26 |
27 | [Embed(source="../embed/penguin_moving.xml", mimeType="application/octet-stream")]
28 | private var MovingXML:Class;
29 | [Embed(source="../embed/penguin_moving.png")]
30 | private var MovingTexture:Class;
31 |
32 | [Embed(source="../embed/penguin_waving.xml", mimeType="application/octet-stream")]
33 | private var WavingXML:Class;
34 | [Embed(source="../embed/penguin_waving.png")]
35 | private var WavingTexture:Class;
36 |
37 | [Embed(source="../embed/bullet.png")]
38 | private var BulletPNG:Class;
39 |
40 | private var _landscape:Image;
41 | private var _landY:int;
42 | private var _penguin:Sprite;
43 | private var _grass:Image;
44 | private var _moving:MovieClip;
45 | private var _waving:MovieClip;
46 |
47 | private var _dPad:DPad;
48 | private var _leftPad:AxisPad;
49 | private var _rightPad:GroupPad;
50 |
51 | private var _bullets:Sprite;
52 | private var _bulletDistance:int = 0;
53 |
54 | // **************************************************** main
55 | public function MyPenguin()
56 | {
57 | addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
58 |
59 | // <----- create DPad
60 | _dPad = new DPad();
61 | _leftPad = _dPad.leftPad as AxisPad;
62 | _rightPad = _dPad.rightPad as GroupPad;
63 | Starling.current.nativeStage.addChild(_dPad);
64 |
65 | // <----- create monitor
66 | Starling.current.nativeStage.addChild(new Stats());
67 | }
68 |
69 | // **************************************************** event - Sprite
70 | private function addedToStageHandler(event:Event):void
71 | {
72 | var w:int = this.stage.stageWidth;
73 | var h:int = this.stage.stageHeight;
74 |
75 | // <----- cache variable
76 | _bulletDistance = w/2;
77 |
78 | // <----- add landscape
79 | _landscape = Image.fromBitmap(new LandscapeJPG());
80 | _landscape.scaleX = _landscape.scaleY = h/_landscape.height;
81 | this.addChild(_landscape);
82 |
83 | // <----- add bullet container
84 | _bullets = new Sprite();
85 | this.addChild(_bullets);
86 |
87 | // <----- add penguin
88 | _penguin = new Sprite();
89 | this.addChild(_penguin);
90 |
91 | // <----- add grass
92 | _grass = Image.fromBitmap(new GrassPNG());
93 | _grass.scaleX = _grass.scaleY = _landscape.scaleX;
94 | this.addChild(_grass);
95 |
96 | // <----- create texture
97 | var movingTexture:Texture = Texture.fromBitmap(new MovingTexture());
98 | var movingXml:XML = XML(new MovingXML());
99 | var movingAtlas:TextureAtlas = new TextureAtlas(movingTexture, movingXml);
100 | var wavingTexture:Texture = Texture.fromBitmap(new WavingTexture());
101 | var wavingXml:XML = XML(new WavingXML());
102 | var wavingAtlas:TextureAtlas = new TextureAtlas(wavingTexture, wavingXml);
103 |
104 | // <----- create MovieClip
105 | _moving = new MovieClip(movingAtlas.getTextures("Penguin Moving"), 30);
106 | _waving = new MovieClip(wavingAtlas.getTextures("Penguin Waving"), 30);
107 | _penguin.addChild(_moving);
108 | _penguin.addChild(_waving);
109 |
110 | // <----- activate MovieClip
111 | Starling.juggler.add(_moving);
112 | Starling.juggler.add(_waving);
113 |
114 | // <----- set properties
115 | _moving.x = _waving.x = -_moving.width/2;
116 | _moving.y = _waving.y = -_moving.height;
117 | _penguin.x = w/2;
118 | _penguin.y = _landY = int(h/9*8);
119 | _moving.visible = true;
120 | _waving.visible = false;
121 | _moving.stop();
122 | _waving.stop();
123 |
124 | // <----- add listener
125 | this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
126 | }
127 | private function enterFrameHandler(event:Event):void{
128 | var v1:int = _leftPad.value;
129 | var v2:int = _rightPad.value;
130 |
131 | if(v1 & AxisPad.LEFT)
132 | _penguin.x -= 2;
133 | if(v1 & AxisPad.RIGHT)
134 | _penguin.x += 2;
135 | if((v1 & AxisPad.UP) && _penguin.y==_landY)
136 | TweenLite.to(_penguin, 0.2, {y:_landY-50, onComplete:jumpCompleteHandler, ease:Quad.easeOut});
137 | if(v1>0)
138 | playMoving();
139 |
140 | if(v2 & GroupPad.A_BUTTON)
141 | playWaving();
142 | if(v2 & GroupPad.B_BUTTON && _bullets.numChildren==0){
143 | // <----- create a bullet
144 | var bullet:Image = Image.fromBitmap(new BulletPNG());
145 | var targetX:Number = _penguin.x + _bulletDistance;
146 | bullet.x = _penguin.x;
147 | bullet.y = _penguin.y - 80;
148 | _bullets.addChild(bullet);
149 |
150 | // <----- animate the bullet
151 | TweenLite.to(bullet, 1, {x:targetX, onComplete:bulletCompleteHandler, onCompleteParams:[bullet], ease:Linear.easeNone});
152 | }
153 |
154 | if(v1+v2==0)
155 | stopMotion();
156 | }
157 |
158 | // **************************************************** private method
159 | private function playMoving():void{
160 | _moving.visible = true;
161 | _waving.visible = false;
162 | _moving.play();
163 | _waving.stop();
164 | }
165 | private function playWaving():void{
166 | _moving.visible = false;
167 | _waving.visible = true;
168 | _moving.stop();
169 | _waving.play();
170 | }
171 | private function stopMotion():void{
172 | _moving.visible = true;
173 | _waving.visible = false;
174 | _moving.stop();
175 | _waving.stop();
176 | }
177 |
178 | // **************************************************** event - TweenLite
179 | private function jumpCompleteHandler():void{
180 | TweenLite.to(_penguin, 0.2, {y:_landY, ease:Quad.easeIn});
181 | }
182 | private function bulletCompleteHandler(bullet:Image):void{
183 | _bullets.removeChild(bullet);
184 | }
185 | }
186 | }
--------------------------------------------------------------------------------
/as3dpad_example/src/example01_basic.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | import duckleg.dpad.AxisPad;
4 | import duckleg.dpad.DPad;
5 | import duckleg.dpad.DPadEvent;
6 | import duckleg.dpad.GroupPad;
7 |
8 | import flash.display.Bitmap;
9 | import flash.display.Sprite;
10 | import flash.display.StageAlign;
11 | import flash.display.StageScaleMode;
12 | import flash.events.Event;
13 |
14 | import net.hires.debug.Stats;
15 |
16 | [SWF(frameRate="60", backgroundColor="#FFFFFF")]
17 | public class example01_basic extends Sprite
18 | {
19 | [Embed(source="../embed/penguin.png")]
20 | private var PenguinPNG:Class;
21 |
22 | private var _dPad:DPad;
23 | private var _penguin:Sprite;
24 |
25 | // **************************************************** main
26 | public function example01_basic()
27 | {
28 | this.stage.align = StageAlign.TOP_LEFT;
29 | this.stage.scaleMode = StageScaleMode.NO_SCALE;
30 |
31 | // <----- add image
32 | var bitmap:Bitmap = new PenguinPNG() as Bitmap;
33 | bitmap.x = -bitmap.width/2;
34 | bitmap.y = -bitmap.height/2;
35 | bitmap.smoothing = true;
36 | _penguin = new Sprite();
37 | _penguin.x = 200;
38 | _penguin.y = 100;
39 | _penguin.addChild(bitmap);
40 | this.addChild(_penguin);
41 |
42 | // <----- use default DPad
43 | _dPad = new DPad();
44 | this.addChild(_dPad);
45 |
46 | // <----- add listener
47 | this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
48 |
49 | // !----- for desktop development - please press "WASD" on keyboard
50 | _dPad.leftPad.addEventListener(DPadEvent.TOUCH_PRESS, touchPressHandler);
51 | _dPad.leftPad.addEventListener(DPadEvent.TOUCH_RELEASE, touchReleaseHandler);
52 |
53 | // !----- for desktop development - please press "m,./" on keyboard
54 | _dPad.rightPad.addEventListener(DPadEvent.TOUCH_PRESS_A, touchPressAHandler);
55 | _dPad.rightPad.addEventListener(DPadEvent.TOUCH_PRESS_B, touchPressBHandler);
56 | _dPad.rightPad.addEventListener(DPadEvent.TOUCH_RELEASE_A, touchReleaseAHandler);
57 | _dPad.rightPad.addEventListener(DPadEvent.TOUCH_RELEASE_B, touchReleaseBHandler);
58 |
59 | // <----- create monitor
60 | this.stage.addChild(new Stats());
61 | }
62 |
63 | // **************************************************** event - Sprite
64 | private function enterFrameHandler(event:Event):void{
65 | var v1:int = _dPad.leftPad.value; // <----- values of X and Y-axes
66 | var v2:int = _dPad.rightPad.value; // <----- values of A and B buttons
67 |
68 | if(v1 & AxisPad.LEFT)
69 | _penguin.x -= 10;
70 | if(v1 & AxisPad.RIGHT)
71 | _penguin.x += 10;
72 | if(v1 & AxisPad.UP)
73 | _penguin.y -= 10;
74 | if(v1 & AxisPad.DOWN)
75 | _penguin.y += 10;
76 |
77 | if(v2 & GroupPad.A_BUTTON)
78 | _penguin.rotation -= 5;
79 | if(v2 & GroupPad.B_BUTTON)
80 | _penguin.rotation += 5;
81 | }
82 |
83 | // **************************************************** event - AxisPad
84 | private function touchPressHandler(event:DPadEvent):void{
85 | trace("press AxisPad: " + event.target);
86 | }
87 | private function touchReleaseHandler(event:DPadEvent):void{
88 | trace("release AxisPad: " + event.target);
89 | }
90 |
91 | // **************************************************** event - GroupPad
92 | private function touchPressAHandler(event:DPadEvent):void{
93 | trace("press A: " + event.target);
94 | }
95 | private function touchPressBHandler(event:DPadEvent):void{
96 | trace("press B: " + event.target);
97 | }
98 | private function touchReleaseAHandler(event:DPadEvent):void{
99 | trace("release A: " + event.target);
100 | }
101 | private function touchReleaseBHandler(event:DPadEvent):void{
102 | trace("release B: " + event.target);
103 | }
104 | }
105 | }
--------------------------------------------------------------------------------
/as3dpad_example/src/example02_custom_UI.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | import duckleg.dpad.AxisPad;
4 | import duckleg.dpad.BasePad;
5 | import duckleg.dpad.DPad;
6 | import duckleg.dpad.GroupButton;
7 | import duckleg.dpad.GroupPad;
8 |
9 | import flash.display.Bitmap;
10 | import flash.display.BitmapData;
11 | import flash.display.Sprite;
12 | import flash.display.StageAlign;
13 | import flash.display.StageScaleMode;
14 | import flash.events.Event;
15 |
16 | import net.hires.debug.Stats;
17 |
18 | [SWF(frameRate="60", backgroundColor="#FFFFFF")]
19 | public class example02_custom_UI extends Sprite
20 | {
21 | [Embed(source="../embed/axisBase01.png")]
22 | private var axisBasePNG:Class;
23 | [Embed(source="../embed/axisStick01.png")]
24 | private var axisStickPNG:Class;
25 | [Embed(source="../embed/axisStickPress01.png")]
26 | private var axisSticPresskPNG:Class;
27 | [Embed(source="../embed/buttonStick01.png")]
28 | private var buttonStick01PNG:Class;
29 | [Embed(source="../embed/buttonStickPress01.png")]
30 | private var buttonStickPress01PNG:Class;
31 | [Embed(source="../embed/buttonStick02.png")]
32 | private var buttonStick02PNG:Class;
33 | [Embed(source="../embed/buttonStickPress02.png")]
34 | private var buttonStickPress02PNG:Class;
35 |
36 | private var _dPad:DPad;
37 | private var _penguin:Sprite;
38 |
39 | // **************************************************** main
40 | public function example02_custom_UI()
41 | {
42 | this.stage.align = StageAlign.TOP_LEFT;
43 | this.stage.scaleMode = StageScaleMode.NO_SCALE;
44 |
45 | // <----- custom graphics
46 | var bmp01:BitmapData = (new axisBasePNG() as Bitmap).bitmapData;
47 | var bmp02:BitmapData = (new axisStickPNG() as Bitmap).bitmapData;
48 | var bmp03:BitmapData = (new axisSticPresskPNG() as Bitmap).bitmapData;
49 | var bmp04:BitmapData = (new buttonStick01PNG() as Bitmap).bitmapData;
50 | var bmp05:BitmapData = (new buttonStickPress01PNG() as Bitmap).bitmapData;
51 | var bmp06:BitmapData = (new buttonStick01PNG() as Bitmap).bitmapData;
52 | var bmp07:BitmapData = (new buttonStickPress01PNG() as Bitmap).bitmapData;
53 | var bmp08:BitmapData = (new buttonStick02PNG() as Bitmap).bitmapData;
54 | var bmp09:BitmapData = (new buttonStickPress02PNG() as Bitmap).bitmapData;
55 |
56 | // <----- create AxisPad - X and Y-axes
57 | var axisPad:AxisPad = new AxisPad(BasePad.VALIGN_BOTTOM, bmp01, bmp02, bmp03);
58 |
59 | // <----- create GroupPad - A and B buttons
60 | var aButton:GroupButton = new GroupButton(GroupPad.A_BUTTON, bmp06, bmp07);
61 | var bButton:GroupButton = new GroupButton(GroupPad.B_BUTTON, bmp08, bmp09);
62 | aButton.x = -120;
63 | aButton.y = 0;
64 | bButton.x = 0;
65 | bButton.y = 0;
66 | var buttons:Vector. = new Vector.;
67 | buttons.push(aButton);
68 | buttons.push(bButton);
69 | var defaultPosition:Boolean = false; // <----- use custom position
70 | var groupPad:GroupPad = new GroupPad(BasePad.VALIGN_BOTTOM, buttons, defaultPosition);
71 |
72 | // <----- create DPad
73 | _dPad = new DPad(axisPad, groupPad);
74 | this.addChild(_dPad);
75 |
76 | // <----- add listener
77 | this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
78 |
79 | // <----- create monitor
80 | this.stage.addChild(new Stats());
81 | }
82 |
83 | // **************************************************** event - Sprite
84 | private function enterFrameHandler(event:Event):void{
85 | trace(_dPad);
86 | }
87 | }
88 | }
--------------------------------------------------------------------------------
/as3dpad_example/src/example03_double_AxisPad.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | import com.greensock.TweenLite;
4 |
5 | import duckleg.dpad.AxisPad;
6 | import duckleg.dpad.BasePad;
7 | import duckleg.dpad.DPad;
8 |
9 | import flash.display.Bitmap;
10 | import flash.display.Sprite;
11 | import flash.display.StageAlign;
12 | import flash.display.StageScaleMode;
13 | import flash.events.Event;
14 |
15 | import net.hires.debug.Stats;
16 |
17 | [SWF(frameRate="60", backgroundColor="#FFFFFF")]
18 | public class example03_double_AxisPad extends Sprite
19 | {
20 | [Embed(source="../embed/aeroplane.png")]
21 | private var AeroplanePNG:Class;
22 |
23 | [Embed(source="../embed/bullet.png")]
24 | private var BulletPNG:Class;
25 |
26 | private var _leftPad:AxisPad;
27 | private var _rightPad:AxisPad;
28 | private var _dPad:DPad;
29 | private var _bullets:Sprite;
30 | private var _aeroplane:Sprite;
31 | private var _bulletDistance:int = 0;
32 |
33 | // **************************************************** main
34 | public function example03_double_AxisPad()
35 | {
36 | this.stage.align = StageAlign.TOP_LEFT;
37 | this.stage.scaleMode = StageScaleMode.NO_SCALE;
38 |
39 | // <----- add listener
40 | this.addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
41 | }
42 |
43 | // **************************************************** event - Sprite
44 | private function enterFrameHandler(event:Event):void{
45 | // <----- if the left pad is pressed, change rotation of the aeroplane
46 | if(_leftPad.value>0)
47 | TweenLite.to(_aeroplane, 0.5, {rotation:_leftPad.radians/Math.PI*180});
48 |
49 | // <----- if the right pad is pressed, create a bullet
50 | if(_rightPad.value>0){
51 | var bullet:Bitmap = new BulletPNG() as Bitmap;
52 | var targetX:Number = BasePad.getPolarX(_aeroplane.x, _rightPad.radians, _bulletDistance);
53 | var targetY:Number = BasePad.getPolarY(_aeroplane.y, _rightPad.radians, _bulletDistance);
54 | bullet.x = _aeroplane.x;
55 | bullet.y = _aeroplane.y;
56 | _bullets.addChild(bullet);
57 |
58 | // <----- animate the bullet
59 | TweenLite.to(bullet, 2, {x:targetX, y:targetY, onComplete:bulletCompleteHandler, onCompleteParams:[bullet]});
60 | }
61 | }
62 | private function addedToStageHandler(event:Event):void{
63 | // <----- add bullet container
64 | _bullets = new Sprite();
65 | this.addChild(_bullets);
66 |
67 | // <----- add image
68 | var bitmap:Bitmap = new AeroplanePNG() as Bitmap;
69 | bitmap.x = -bitmap.width/2;
70 | bitmap.y = -bitmap.height/2;
71 | bitmap.smoothing = true;
72 | _aeroplane = new Sprite();
73 | _aeroplane.addChild(bitmap);
74 | this.addChild(_aeroplane);
75 |
76 | // <----- create double AxisPad
77 | _leftPad = new AxisPad();
78 | _rightPad = new AxisPad();
79 |
80 | // <----- create DPad
81 | _dPad = new DPad(_leftPad, _rightPad);
82 | this.addChild(_dPad);
83 |
84 | // <----- add listener
85 | this.stage.addEventListener(Event.RESIZE, resizeHandler);
86 | this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
87 |
88 | // <----- key mapping for the second AxisPad (just for desktop testing)
89 | _rightPad.leftKeycode = 37; // LeftArrow keycode
90 | _rightPad.rightKeycode = 39; // RightArrow keycode
91 | _rightPad.upKeycode = 38; // UpArrow keycode
92 | _rightPad.downKeycode = 40; // DownArrow keycode
93 |
94 | // <----- create monitor
95 | this.stage.addChild(new Stats());
96 |
97 | // <----- the first setup
98 | resizeHandler(null);
99 | }
100 | private function resizeHandler(event:Event):void{
101 | _aeroplane.x = this.stage.stageWidth/2;
102 | _aeroplane.y = this.stage.stageHeight/2;
103 | _bulletDistance = this.stage.stageWidth + this.stage.stageHeight;
104 | }
105 |
106 | // **************************************************** event - TweenLite
107 | private function bulletCompleteHandler(bullet:Bitmap):void{
108 | _bullets.removeChild(bullet);
109 | }
110 | }
111 | }
--------------------------------------------------------------------------------
/as3dpad_example/src/example04_touch9Grid.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | import duckleg.dpad.DPad;
4 | import duckleg.dpad.DPadEvent;
5 |
6 | import flash.display.Bitmap;
7 | import flash.display.Sprite;
8 | import flash.display.StageAlign;
9 | import flash.display.StageScaleMode;
10 | import flash.events.Event;
11 | import flash.text.TextField;
12 | import flash.text.TextFormat;
13 |
14 | [SWF(frameRate="60", backgroundColor="#FFFFFF")]
15 | public class example04_touch9Grid extends Sprite
16 | {
17 | [Embed(source="../embed/icon_music.png")]
18 | private var MusicPNG:Class;
19 | [Embed(source="../embed/icon_pause.png")]
20 | private var PausePNG:Class;
21 | [Embed(source="../embed/icon_setting.png")]
22 | private var SettingPNG:Class;
23 |
24 | private var _dPad:DPad;
25 | private var _music:Bitmap;
26 | private var _pause:Bitmap;
27 | private var _setting:Bitmap;
28 | private var _textFormat:TextFormat;
29 | private var _message:TextField;
30 |
31 | // **************************************************** main
32 | public function example04_touch9Grid()
33 | {
34 | this.stage.align = StageAlign.TOP_LEFT;
35 | this.stage.scaleMode = StageScaleMode.NO_SCALE;
36 |
37 | // <----- add image
38 | _music = new MusicPNG() as Bitmap;
39 | _pause = new PausePNG() as Bitmap;
40 | _setting = new SettingPNG() as Bitmap;
41 | this.addChild(_music);
42 | this.addChild(_pause);
43 | this.addChild(_setting);
44 |
45 | // <----- add debug message
46 | _textFormat = new TextFormat("Arial", 16, 0x000000, true, false, false, null, null, "center");
47 | _message = new TextField();
48 | _message.width = 300;
49 | _message.text = "Please touch the icon.";
50 | _message.setTextFormat(_textFormat);
51 | this.addChild(_message);
52 |
53 | // <----- create DPad and enable touch9Grid
54 | _dPad = new DPad(null, null, true);
55 | this.addChild(_dPad);
56 |
57 | // <----- add listener
58 | this.addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
59 |
60 | // !----- for desktop development - please press "123456789" on keyboard
61 | _dPad.addEventListener(DPadEvent.TOUCH_PRESS_9_GRID, touchPress9GridHandler);
62 | }
63 |
64 | // **************************************************** event - Sprite
65 | private function addedToStageHandler(event:Event):void{
66 | this.stage.addEventListener(Event.RESIZE, resizeHandler);
67 |
68 | // <----- the first setup
69 | resizeHandler(null);
70 | }
71 | private function resizeHandler(event:Event):void{
72 | var w:int = this.stage.stageWidth;
73 | var h:int = this.stage.stageHeight;
74 |
75 | _music.x = 0;
76 | _pause.x = w/2 - _pause.width/2;
77 | _setting.x = w - _setting.width;
78 |
79 | _message.x = w/2 - _message.width/2;
80 | _message.y = h/2;
81 | }
82 |
83 | // **************************************************** event - DPad
84 | private function touchPress9GridHandler(event:DPadEvent):void{
85 | if(_dPad.touch9Value & DPad.TOUCH_LEFT_TOP)
86 | _message.text = "You press the Music icon.";
87 | else if(_dPad.touch9Value & DPad.TOUCH_TOP)
88 | _message.text = "You press the Pause icon.";
89 | else if(_dPad.touch9Value & DPad.TOUCH_RIGHT_TOP)
90 | _message.text = "You press the Setting icon.";
91 | else
92 | _message.text = "No icon is pressed. (x:"+int(_dPad.touch.x)+", y:"+int(_dPad.touch.y)+")";
93 |
94 | _message.setTextFormat(_textFormat);
95 | }
96 | }
97 | }
--------------------------------------------------------------------------------
/as3dpad_example/src/example05_starling.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | import duckleg.starling.MyPenguin;
4 |
5 | import flash.display.Sprite;
6 | import flash.display.StageAlign;
7 | import flash.display.StageScaleMode;
8 | import flash.events.Event;
9 |
10 | import starling.core.Starling;
11 |
12 | [SWF(frameRate="60", backgroundColor="#FFFFFF")]
13 | public class example05_starling extends Sprite
14 | {
15 | // **************************************************** main
16 | public function example05_starling()
17 | {
18 | this.stage.align = StageAlign.TOP_LEFT;
19 | this.stage.scaleMode = StageScaleMode.NO_SCALE;
20 |
21 | // <----- add listener
22 | addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
23 | }
24 |
25 | // **************************************************** event - Sprite
26 | private function addedToStageHandler(event:Event):void{
27 | this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
28 | }
29 | private function enterFrameHandler(event:Event):void{
30 | // <----- remove listener
31 | this.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
32 |
33 | // <----- craete Starling
34 | var mStarling:Starling = new Starling(MyPenguin, this.stage);
35 | mStarling.start();
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/as3dpad_example/src/net/hires/debug/Stats.as:
--------------------------------------------------------------------------------
1 | /**
2 | * stats.as
3 | * https://github.com/mrdoob/Hi-ReS-Stats
4 | *
5 | * Released under MIT license:
6 | * http://www.opensource.org/licenses/mit-license.php
7 | *
8 | * How to use:
9 | *
10 | * addChild( new Stats() );
11 | *
12 | **/
13 |
14 | package net.hires.debug {
15 |
16 | import flash.display.BitmapData;
17 | import flash.display.Sprite;
18 | import flash.events.Event;
19 | import flash.events.MouseEvent;
20 | import flash.geom.Matrix;
21 | import flash.geom.Rectangle;
22 | import flash.system.System;
23 | import flash.text.StyleSheet;
24 | import flash.text.TextField;
25 | import flash.utils.getTimer;
26 |
27 | public class Stats extends Sprite {
28 |
29 | protected const WIDTH : uint = 70;
30 | protected const HEIGHT : uint = 100;
31 |
32 | protected var xml : XML;
33 |
34 | protected var text : TextField;
35 | protected var style : StyleSheet;
36 |
37 | protected var timer : uint;
38 | protected var fps : uint;
39 | protected var ms : uint;
40 | protected var ms_prev : uint;
41 | protected var mem : Number;
42 | protected var mem_max : Number;
43 |
44 | protected var graph : BitmapData;
45 | protected var rectangle : Rectangle;
46 |
47 | protected var fps_graph : uint;
48 | protected var mem_graph : uint;
49 | protected var mem_max_graph : uint;
50 |
51 | protected var colors : Colors = new Colors();
52 |
53 | /**
54 | * Stats FPS, MS and MEM, all in one.
55 | */
56 | public function Stats() : void {
57 |
58 | mem_max = 0;
59 |
60 | xml = FPS:MS:MEM:MAX:;
61 |
62 | style = new StyleSheet();
63 | style.setStyle('xml', {fontSize:'9px', fontFamily:'_sans', leading:'-2px'});
64 | style.setStyle('fps', {color: hex2css(colors.fps)});
65 | style.setStyle('ms', {color: hex2css(colors.ms)});
66 | style.setStyle('mem', {color: hex2css(colors.mem)});
67 | style.setStyle('memMax', {color: hex2css(colors.memmax)});
68 |
69 | text = new TextField();
70 | text.width = WIDTH;
71 | text.height = 50;
72 | text.styleSheet = style;
73 | text.condenseWhite = true;
74 | text.selectable = false;
75 | text.mouseEnabled = false;
76 |
77 | rectangle = new Rectangle(WIDTH - 1, 0, 1, HEIGHT - 50);
78 |
79 | addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
80 | addEventListener(Event.REMOVED_FROM_STAGE, destroy, false, 0, true);
81 |
82 | }
83 |
84 | private function init(e : Event) : void {
85 |
86 | graphics.beginFill(colors.bg);
87 | graphics.drawRect(0, 0, WIDTH, HEIGHT);
88 | graphics.endFill();
89 |
90 | addChild(text);
91 |
92 | graph = new BitmapData(WIDTH, HEIGHT - 50, false, colors.bg);
93 | graphics.beginBitmapFill(graph, new Matrix(1, 0, 0, 1, 0, 50));
94 | graphics.drawRect(0, 50, WIDTH, HEIGHT - 50);
95 |
96 | addEventListener(MouseEvent.CLICK, onClick);
97 | addEventListener(Event.ENTER_FRAME, update);
98 |
99 | }
100 |
101 | private function destroy(e : Event) : void {
102 |
103 | graphics.clear();
104 |
105 | while(numChildren > 0)
106 | removeChildAt(0);
107 |
108 | graph.dispose();
109 |
110 | removeEventListener(MouseEvent.CLICK, onClick);
111 | removeEventListener(Event.ENTER_FRAME, update);
112 |
113 | }
114 |
115 | private function update(e : Event) : void {
116 |
117 | timer = getTimer();
118 |
119 | if( timer - 1000 > ms_prev ) {
120 |
121 | ms_prev = timer;
122 | mem = Number((System.totalMemory * 0.000000954).toFixed(3));
123 | mem_max = mem_max > mem ? mem_max : mem;
124 |
125 | fps_graph = Math.min(graph.height, ( fps / stage.frameRate ) * graph.height);
126 | mem_graph = Math.min(graph.height, Math.sqrt(Math.sqrt(mem * 5000))) - 2;
127 | mem_max_graph = Math.min(graph.height, Math.sqrt(Math.sqrt(mem_max * 5000))) - 2;
128 |
129 | graph.scroll(-1, 0);
130 |
131 | graph.fillRect(rectangle, colors.bg);
132 | graph.setPixel(graph.width - 1, graph.height - fps_graph, colors.fps);
133 | graph.setPixel(graph.width - 1, graph.height - ( ( timer - ms ) >> 1 ), colors.ms);
134 | graph.setPixel(graph.width - 1, graph.height - mem_graph, colors.mem);
135 | graph.setPixel(graph.width - 1, graph.height - mem_max_graph, colors.memmax);
136 |
137 | xml.fps = "FPS: " + fps + " / " + stage.frameRate;
138 | xml.mem = "MEM: " + mem;
139 | xml.memMax = "MAX: " + mem_max;
140 |
141 | fps = 0;
142 |
143 | }
144 |
145 | fps++;
146 |
147 | xml.ms = "MS: " + (timer - ms);
148 | ms = timer;
149 |
150 | text.htmlText = xml;
151 | }
152 |
153 | private function onClick(e : MouseEvent) : void {
154 |
155 | mouseY / height > .5 ? stage.frameRate-- : stage.frameRate++;
156 | xml.fps = "FPS: " + fps + " / " + stage.frameRate;
157 | text.htmlText = xml;
158 |
159 | }
160 |
161 | // .. Utils
162 |
163 | private function hex2css( color : int ) : String {
164 |
165 | return "#" + color.toString(16);
166 |
167 | }
168 |
169 | }
170 |
171 | }
172 |
173 | class Colors {
174 |
175 | public var bg : uint = 0x000033;
176 | public var fps : uint = 0xffff00;
177 | public var ms : uint = 0x00ff00;
178 | public var mem : uint = 0x00ffff;
179 | public var memmax : uint = 0xff0070;
180 |
181 | }
--------------------------------------------------------------------------------
/as3dpad_example/src/net/hires/debug/Stats.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * stats.hx
3 | * http://github.com/mrdoob/stats.as
4 | *
5 | * Released under MIT license:
6 | * http://www.opensource.org/licenses/mit-license.php
7 | *
8 | * How to use:
9 | *
10 | * addChild( new Stats() );
11 | *
12 | **/
13 |
14 | package net.hires.debug;
15 |
16 | import flash.display.BitmapData;
17 | import flash.display.Sprite;
18 | import flash.display.Stage;
19 | import flash.events.Event;
20 | import flash.events.MouseEvent;
21 | import flash.geom.Matrix;
22 | import flash.geom.Rectangle;
23 | import flash.system.System;
24 | import flash.text.StyleSheet;
25 | import flash.text.TextField;
26 | import flash.xml.XML;
27 |
28 |
29 | class Stats extends Sprite {
30 |
31 | static inline var GRAPH_WIDTH : Int = 70;
32 | static inline var XPOS : Int = 69;//width - 1
33 | static inline var GRAPH_HEIGHT : Int = 50;
34 | static inline var TEXT_HEIGHT : Int = 50;
35 |
36 | private var xml : XML;
37 |
38 | private var text : TextField;
39 | private var style : StyleSheet;
40 |
41 | private var timer : Int;
42 | private var fps : Int;
43 | private var ms : Int;
44 | private var ms_prev : Int;
45 | private var mem : Float;
46 | private var mem_max : Float;
47 |
48 | private var graph : BitmapData;
49 | private var rectangle : Rectangle;
50 |
51 | private var fps_graph : Int;
52 | private var mem_graph : Int;
53 | private var ms_graph : Int;
54 | private var mem_max_graph : Int;
55 | private var _stage:Stage;
56 |
57 | /**
58 | * Stats FPS, MS and MEM, all in one.
59 | */
60 | public function new() {
61 |
62 | super();
63 | mem_max = 0;
64 | fps = 0;
65 |
66 |
67 | xml = new XML("FPS:MS:MEM:MAX:");
68 |
69 | style = new StyleSheet();
70 | style.setStyle('xml', {fontSize:'9px', fontFamily:'_sans', leading:'-2px'});
71 | style.setStyle('fps', {color: Colors.fpsCSS });
72 | style.setStyle('ms', {color: Colors.msCSS });
73 | style.setStyle('mem', {color: Colors.memCSS });
74 | style.setStyle('memMax', {color: Colors.memmaxCSS });
75 |
76 | text = new TextField();
77 | text.width = GRAPH_WIDTH;
78 | text.height = TEXT_HEIGHT;
79 | text.styleSheet = style;
80 | text.condenseWhite = true;
81 | text.selectable = false;
82 | text.mouseEnabled = false;
83 |
84 | rectangle = new Rectangle(GRAPH_WIDTH - 1, 0, 1, GRAPH_HEIGHT);
85 |
86 | this.addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
87 | this.addEventListener(Event.REMOVED_FROM_STAGE, destroy, false, 0, true);
88 |
89 | }
90 |
91 | private function init(e : Event) {
92 |
93 | _stage = flash.Lib.current.stage;
94 | graphics.beginFill(Colors.bg);
95 | graphics.drawRect(0, 0, GRAPH_WIDTH, TEXT_HEIGHT);
96 | graphics.endFill();
97 |
98 | this.addChild(text);
99 |
100 | graph = new BitmapData(GRAPH_WIDTH, GRAPH_HEIGHT, false, Colors.bg);
101 | graphics.beginBitmapFill(graph, new Matrix(1, 0, 0, 1, 0, TEXT_HEIGHT));
102 | graphics.drawRect(0, TEXT_HEIGHT, GRAPH_WIDTH, GRAPH_HEIGHT);
103 |
104 | this.addEventListener(Event.ENTER_FRAME, update);
105 |
106 | }
107 |
108 | private function destroy(e : Event) {
109 |
110 | graphics.clear();
111 |
112 | while(numChildren > 0)
113 | removeChildAt(0);
114 |
115 | graph.dispose();
116 |
117 | removeEventListener(Event.ENTER_FRAME, update);
118 |
119 | }
120 |
121 | private function update(e : Event) {
122 |
123 | timer = flash.Lib.getTimer();
124 |
125 | //after a second has passed
126 | if( timer - 1000 > ms_prev ) {
127 |
128 | mem = System.totalMemory * 0.000000954;
129 | mem_max = mem_max > mem ? mem_max : mem;
130 |
131 | fps_graph = GRAPH_HEIGHT - Std.int( Math.min(GRAPH_HEIGHT, ( fps / _stage.frameRate ) * GRAPH_HEIGHT) );
132 |
133 | mem_graph = GRAPH_HEIGHT - normalizeMem(mem);
134 | mem_max_graph = GRAPH_HEIGHT - normalizeMem(mem_max);
135 | //milliseconds since last frame -- this fluctuates quite a bit
136 | ms_graph = Std.int( GRAPH_HEIGHT - ( ( timer - ms ) >> 1 ));
137 | graph.scroll(-1, 0);
138 |
139 | graph.fillRect(rectangle, Colors.bg);
140 | graph.lock();
141 | graph.setPixel(XPOS, fps_graph, Colors.fps);
142 | graph.setPixel(XPOS, mem_graph, Colors.mem);
143 | graph.setPixel(XPOS, mem_max_graph, Colors.memmax);
144 | graph.setPixel(XPOS, ms_graph, Colors.ms);
145 | graph.unlock();
146 |
147 | xml.fps = "FPS: " + fps + " / " + stage.frameRate;
148 | xml.mem = "MEM: " + mem;
149 | xml.memMax = "MAX: " + mem_max;
150 |
151 | //reset frame and time counters
152 | fps = 0;
153 | ms_prev = timer;
154 |
155 | return;
156 | }
157 | //increment number of frames which have occurred in current second
158 | fps++;
159 |
160 | xml.ms = "MS: " + (timer - ms);
161 | ms = timer;
162 |
163 | text.htmlText = xml.toString();
164 | }
165 |
166 |
167 |
168 | function normalizeMem(_mem:Float):Int {
169 | return Std.int( Math.min( GRAPH_HEIGHT, Math.sqrt(Math.sqrt(_mem * 5000)) ) - 2);
170 | }
171 |
172 | }
173 |
174 | class Colors {
175 |
176 | public static inline var bg : Int = 0x000033;
177 | public static inline var fps : Int = 0xffff00;
178 | public static inline var ms : Int = 0x00ff00;
179 | public static inline var mem : Int = 0x00ffff;
180 | public static inline var memmax : Int = 0xff0070;
181 | public static inline var bgCSS : String = "#000033";
182 | public static inline var fpsCSS : String = "#ffff00";
183 | public static inline var msCSS : String = "#00ff00";
184 | public static inline var memCSS : String = "#00ffff";
185 | public static inline var memmaxCSS : String = "#ff0070";
186 |
187 | }
188 |
--------------------------------------------------------------------------------