Airconsole controller maker

Post your completed addons to share with the community

Post » Fri Jan 27, 2017 6:30 pm

X3M wrote:@cjbruce Have you tried creating an Airconsole object in your controller and getting the nickname inside an OnDeviceJoin condition?
I think that the nickname that you will get is yours, If I'm not wrong. It is worth a try.


@X3M,

No luck. The OnDeviceJoin condition doesn't fire on the controller side. Just for kicks, I tried an alert with OnDeviceJoin on start of layout, and the alert showed "null" for the airconsole.nicknamejoin because it had not been set yet.
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
48
S
14
G
24
Posts: 400
Reputation: 16,648

Post » Fri Jan 27, 2017 6:35 pm

@X3M,

Also, the console is seeing a lot of handshake errors in the simulator:

Message to 0: {\"handshake\":true}
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
48
S
14
G
24
Posts: 400
Reputation: 16,648

Post » Fri Jan 27, 2017 7:43 pm

@X3M and @Psychokiller1888,

I was poking through the code, and realized that the following lines are duplicated for buttons in the AirConsoleController. If I'm not wrong, this means that "sendHandshake()" will get called twice, and it is redeclaring the sendHandshake function:

Code: Select all
var sendHandshake = function () {
            _this.airconsole.message(AirConsole.SCREEN, {
               handshake: true
            });
         };
         _this.airconsole.onReady = function () {
            sendHandshake();
         };
         _this.airconsole.onMessage = function (device_id, data) {
            if (data.handshake) {
               sendHandshake();
            }
         };


I don't know if the above really affects anything.



Also, I placed an alert in c2runtimectrl.js to verify that messages are getting received by the controller and handled in this.air_console.onMessage (created by the AirConsole plugin, not the AirConsoleController plugin). My alert fires when I place it directly into the code, but a similar alert for the onMessage trigger placed in a Construct 2 event sheet does not fire.
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
48
S
14
G
24
Posts: 400
Reputation: 16,648

Post » Fri Jan 27, 2017 9:44 pm

Findings after more testing:

1. When using a controller created in C2 with the two plugins, OnDeviceJoin is not called in screen.html.
2. The screen doesn't seem to be resizing correctly on my phone (iPhone 7 plus) or iPad. The screen is resizing correctly in the simulator (Nexus 5).
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
48
S
14
G
24
Posts: 400
Reputation: 16,648

Post » Fri Jan 27, 2017 9:45 pm

@cjbruce Yep that's the issue, there should be only one handshake per controller, I'll update later.
Edit: That is weird because it is working fine with the pong demo. Have you tried testing on an Android device?
Edit: Add this line :
Code: Select all
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
To the <head> of controller.html and tell me if it fixes the problem.
Banned User
B
17
S
7
G
23
Posts: 388
Reputation: 13,994

Post » Fri Jan 27, 2017 10:34 pm

X3M wrote:@cjbruce Yep that's the issue, there should be only one handshake per controller, I'll update later.
Edit: That is weird because it is working fine with the pong demo. Have you tried testing on an Android device?
Edit: Add this line :
Code: Select all
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
To the <head> of controller.html and tell me if it fixes the problem.


@X3M,

No luck with the scaling problem. I wonder if it is a javascript issue. My existing code:

Code: Select all
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui" />


The not receiving messages from the screen.html is driving me crazy. I've spent several hours adding alerts in different spots in c2runtimectrl.js and/or in the event sheet. All of the alerts I place directly into the code fire properly, but whenever I try to trigger an alert based on an AirConsole condition (OnDeviceJoin, OnMessage, etc.), I get nothing. I've even tried to fiddle with the ExecJS() expression in Construct 2 to get the status of the message directly, but no luck so far. Maybe I can create a variable at the beginning of the controller.html called "airconsoleMessageFromTheScreen", and set its value directly?

Also, I still can't get the OnDeviceJoin and OnDeviceLeft conditions to work.

I'm getting really flumoxed, and running out of ideas...
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
48
S
14
G
24
Posts: 400
Reputation: 16,648

Post » Fri Jan 27, 2017 10:45 pm

@cjbruce You surely are doing something wrong , does the Pong example work for you ? I recommend that you go from there and examine the event sheet, remember that you need to allow the devices to connect first so that OnDeviceJoin and OnDeviceLeft can work.

Image
Banned User
B
17
S
7
G
23
Posts: 388
Reputation: 13,994

Post » Fri Jan 27, 2017 11:44 pm

X3M wrote:@cjbruce You surely are doing something wrong , does the Pong example work for you ? I recommend that you go from there and examine the event sheet, remember that you need to allow the devices to connect first so that OnDeviceJoin and OnDeviceLeft can work.

Image


@X3M

The pong example works fine, but it does not include an example of sending a message to the controllers other than a handshake.

I'm porting an existing project that has been working for months now, and trying to remake the controllers in C2, instead of by hand.
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
48
S
14
G
24
Posts: 400
Reputation: 16,648

Post » Sat Jan 28, 2017 7:59 am

@cjbruce

Just use the send message from your game to the desired controller. Invent your own format for your state changes, quick dirty exemple:

Image

Listen for the message on your controller

Code: Select all
airConsole.onMessage = function(deviceId, data) {
      if (data.handshake) {
         sendHandshake();
      }
      else if (data == 'displayState1') {
         do your controller changes


As for the nickname, you surely won't tell the controller to ask the screen to get the controller's nickname and make it send it back to the controller....

You have an AirConsole object on your controller, so just get the nickname with it...

Code: Select all
airConsole = new AirConsole({"orientation": "landscape"});
   var nickname = airConsole.getNickname();



As for the controllers not receiving, not getting dunno what, I cannot help sorry. I do not know this plugin and what it generates. I know that the official controller generator does work so I let you solve that with @X3M

This is the behavior: https://puu.sh/tDCKO.png
Image is too big, this forum does not even resize when using [img]

Image
B
33
S
11
G
3
Posts: 226
Reputation: 4,326

Post » Sat Jan 28, 2017 9:04 am

@Psychokiller1888 Ok thanks for the code, I'll implement a OnMessageReceived == "text" in the Controller.
Edit: Ok now you can consider the plugin fully finished, I've added all the remaining features to it such as :
- Controller->Accelerometer&Gyroscope
- Controller->DeviceNickname/Id/PlayerNumber
-Edit profile
-OnMessage "message" Receiver
- Controller->ProfilePictureURL
-Controller->ReceivedMessage
Banned User
B
17
S
7
G
23
Posts: 388
Reputation: 13,994

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: mihirolover and 2 guests