{"action":"created","issue":{"url":"https://api.github.com/repos/GoranM/bdx/issues/570","repository_url":"https://api.github.com/repos/GoranM/bdx","labels_url":"https://api.github.com/repos/GoranM/bdx/issues/570/labels{/name}","comments_url":"https://api.github.com/repos/GoranM/bdx/issues/570/comments","events_url":"https://api.github.com/repos/GoranM/bdx/issues/570/events","html_url":"https://github.com/GoranM/bdx/issues/570","id":138420708,"number":570,"title":"Suggestion: VirtualController","user":{"login":"rafcolson","id":10002909,"avatar_url":"https://avatars.githubusercontent.com/u/10002909?v=3","gravatar_id":"","url":"https://api.github.com/users/rafcolson","html_url":"https://github.com/rafcolson","followers_url":"https://api.github.com/users/rafcolson/followers","following_url":"https://api.github.com/users/rafcolson/following{/other_user}","gists_url":"https://api.github.com/users/rafcolson/gists{/gist_id}","starred_url":"https://api.github.com/users/rafcolson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rafcolson/subscriptions","organizations_url":"https://api.github.com/users/rafcolson/orgs","repos_url":"https://api.github.com/users/rafcolson/repos","events_url":"https://api.github.com/users/rafcolson/events{/privacy}","received_events_url":"https://api.github.com/users/rafcolson/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2016-03-04T09:03:19Z","updated_at":"2016-03-16T12:12:35Z","closed_at":null,"body":"# API VirtualController\r\n\r\nExtends [ArrayList](http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)\\<String>. A collection of names of GameObject's that act as onscreen buttons. Tells if a button is hit, touched or just touched by a mouse or fingers on a touchscreen. Overrides methods of [ArrayList](http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html) for adding and removing names of buttons. Buttons should not have body type ```\"NO_COLLISION\"```.\r\n\r\nWhen created it will be added to ```Bdx.vControllers``` and available for mapping with ```Bdx.imaps```.\r\n___\r\n\r\n### Constructors\r\n\r\n<a name=\"VirtualController\" href=\"#VirtualController\">#</a> **VirtualController**(String prefix=\"\")\r\n\r\nConstructor with optionally a prefix.\r\n\r\n<a name=\"VirtualControllerGameObject\" href=\"#VirtualControllerGameObject\">#</a> **VirtualController**([ArrayList](http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)\\<GameObject> btns, String prefix=\"\")\r\n\r\nConstructor with a list of buttons and optionally a prefix.\r\n\r\n<a name=\"VirtualControllerString\" href=\"#VirtualControllerString\">#</a> **VirtualController**([ArrayList](http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)\\<String> btnNames, String prefix=\"\")\r\n\r\nConstructor with a list of button names and optionally a prefix.\r\n___\r\n\r\n### Fields\r\n\r\n<a name=\"name\" href=\"#name\">#</a> **name** - String\r\n\r\nCustomizable name for use with multiple virtual controllers. For example:\r\n```java\r\nif (Bdx.vControllers.get(\"vGamepad\").hit(\"a\")){\r\n\t// do stuff\r\n}\r\nif (Bdx.vControllers.get(\"vMenu\").hit(\"options\")){\r\n\t// do stuff\r\n}\r\n```\r\n<a name=\"prefix\" href=\"#prefix\">#</a> **prefix** - String\r\n\r\nThe prefix field determines which part of the button name should be ignored in the getters. For example if buttons are named *\"Btn_A\", \"Btn_B\", \"Btn_C\", ...*:\r\n```java\r\npublic class InputController extends GameObject{\r\n\t\r\n\tpublic VirtualController vc;\r\n\t\r\n\tpublic void init(){\r\n\t\tString prefix = \"Btn_\";\r\n\t\tvc = new VirtualController(prefix);\r\n\t\tfor (GameObject g : scene.objects){\r\n\t\t\tif (g.name.startsWith(prefix)){\r\n\t\t\t\tvc.add(g);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void main(){\r\n\t\tvc.update();\r\n\t\t\r\n\t\tif (vc.hit(\"A\")){\r\n\t\t\t// do stuff\r\n\t\t}\r\n\t\tif (vc.hit(\"B\")){\r\n\t\t\t// do stuff\r\n\t\t}\r\n\t\t...\r\n\t}\r\n\t\r\n}\r\n```\r\n<a name=\"hitList\" href=\"#hitList\">#</a> **hit** - [ArrayList](http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)\\<String>\r\n\r\nList of the names of buttons that are hit.\r\n\r\n<a name=\"downList\" href=\"#down\">#</a> **down** - [ArrayList](http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)\\<String>\r\n\r\nList of the names of buttons that are touched.\r\n\r\n<a name=\"upList\" href=\"#upList\">#</a> **up** - [ArrayList](http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)\\<String>\r\n\r\nList of the names of buttons that are just touched.\r\n\r\nAccess to these fields becomes useful when animating the buttons. For example:\r\n```java\r\n\tpublic void main(){\r\n\t\tvc.update();\r\n\t\t\r\n\t\tif (vc.hit()){\r\n\t\t\tfor (String s : vc.hit){\r\n\t\t\t\t((SpriteAnim)scene.objects.get(s).components.get(0)).play(\"hit\");\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif (vc.hit(\"A\")){\r\n\t\t\t\t// do stuff\r\n\t\t\t}\r\n\t\t\t...\r\n\t\t}\r\n\t\t\r\n\t\tfor (String s : vc.up){\r\n\t\t\t((SpriteAnim)scene.objects.get(s).components.get(0)).play(\"up\");\r\n\t\t}\r\n\t}\r\n```\r\n___\r\n\r\n### Methods\r\n\r\n<a name=\"add\" href=\"#add\">#</a> **add**(GameObject btn)\r\n\r\nConvenience function for adding the name of this button.\r\n\r\n<a name=\"remove\" href=\"#remove\">#</a> **remove**(GameObject btn)\r\n\r\nConvenience function for removing the name of this button.\r\n\r\n<a name=\"addAll\" href=\"#addAll\">#</a> **addAll**([ArrayList](http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)\\<GameObject> btns)\r\n\r\nConvenience function for adding the names of these buttons.\r\n\r\n<a name=\"removeAll\" href=\"#removeAll\">#</a> **removeAll**([ArrayList](http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)\\<GameObject> btns)\r\n\r\nConvenience function for removing the names of these buttons.\r\n\r\n<a name=\"hitAny\" href=\"#hitAny\">#</a> **hit**() - boolean\r\n\r\nReturns whether any of the buttons is hit or not.\r\n\r\n<a name=\"downAny\" href=\"#downAny\">#</a> **down**() - boolean\r\n\r\nReturns whether any of the buttons is touched or not.\r\n\r\n<a name=\"upAny\" href=\"#upAny\">#</a> **up**() - boolean\r\n\r\nReturns whether any of the buttons is just touched or not.\r\n\r\n<a name=\"hit\" href=\"#hit\">#</a> **hit**(String s) - boolean\r\n\r\nReturns whether a button with this name is hit or not.\r\n\r\n<a name=\"down\" href=\"#down\">#</a> **down**(String s) - boolean\r\n\r\nReturns whether a button with this name is touched or not.\r\n\r\n<a name=\"up\" href=\"#up\">#</a> **up**(String s) - boolean\r\n\r\nReturns whether a button with this name is just touched or not.\r\n\r\n<a name=\"iHit\" href=\"#iHit\">#</a> **iHit**(String s) - int\r\n\r\nSame as ```hit(s)```, but returns an integer: 1 if true, and 0 if false.\r\n\r\n<a name=\"iDown\" href=\"#iDown\">#</a> **iDown**(String s) - int\r\n\r\nSame as ```down(s)```, but returns an integer: 1 if true, and 0 if false.\r\n\r\n<a name=\"iUp\" href=\"#up\">#</a> **iUp**(String s) - int\r\n\r\nSame as ```up(s)```, but returns an integer: 1 if true, and 0 if false.\r\n\r\n<a name=\"update\" href=\"#up\">#</a> **update**()\r\n\r\nUpdate function that should be called before calling the functions above. For best results it's recommended to call it on a GameObject which uses execution priority (It seems that execution priority is not yet documented in the API, so I'll do this also and reference to it).\r\n\r\n<a name=\"dispose\" href=\"#up\">#</a> **dispose**()\r\n\r\nRemoves this virtual controller from ```Bdx.vControllers```.\r\n___\r\n\r\n# API Bdx\r\n...\r\n<a name=\"vControllers\" href=\"#vControllers\">#</a> **vControllers** - [ArrayListNamed](https://github.com/GoranM/bdx/wiki/API-ArrayListNamed)\\<VirtualController>\r\n\r\nA named list of added virtual controllers. \r\n...\r\n___\r\n\r\n# API InputMaps\r\n...\r\n* VirtualController - \"v:button\" (button -> valid string arg for VirtualController.\\* methods); specifying indices works the same as with gamepads.\r\n\r\n..."},"comment":{"url":"https://api.github.com/repos/GoranM/bdx/issues/comments/197289900","html_url":"https://github.com/GoranM/bdx/issues/570#issuecomment-197289900","issue_url":"https://api.github.com/repos/GoranM/bdx/issues/570","id":197289900,"user":{"login":"rafcolson","id":10002909,"avatar_url":"https://avatars.githubusercontent.com/u/10002909?v=3","gravatar_id":"","url":"https://api.github.com/users/rafcolson","html_url":"https://github.com/rafcolson","followers_url":"https://api.github.com/users/rafcolson/followers","following_url":"https://api.github.com/users/rafcolson/following{/other_user}","gists_url":"https://api.github.com/users/rafcolson/gists{/gist_id}","starred_url":"https://api.github.com/users/rafcolson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rafcolson/subscriptions","organizations_url":"https://api.github.com/users/rafcolson/orgs","repos_url":"https://api.github.com/users/rafcolson/repos","events_url":"https://api.github.com/users/rafcolson/events{/privacy}","received_events_url":"https://api.github.com/users/rafcolson/received_events","type":"User","site_admin":false},"created_at":"2016-03-16T12:12:35Z","updated_at":"2016-03-16T12:12:35Z","body":">Is that what you mean?\r\n\r\nI don't understand what ```customDescriptor(d[0])``` is supposed to represent. And I don't see how such a mechanism would work."}}