Support for Google Chromecast receiver API

For developers using the Construct 2 Javascript SDK

Post » Sun Nov 30, 2014 4:33 am

Hi guys, new here. FANTASTIC game engine.

I'm trying to load in the Javascript library, which I've done so like this:

Code: Select all
   instanceProto.onCreate = function()
   {
      var self = this;
      
      
      // ===================
      //
      // CHROME CAST ENGINE
      //
      // ===================
      
      console.log("Attempting to load cast_receiver.js");
      
      $.ajax({
        url: "http://www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js",
        dataType: "script",
        success: function(){
         console.log("LOADED: cast_receiver.js");
        }
      });
      
      console.log("Finished cast_receiver loading");


I can't figure out how to load this external JS any other way.

Here is the next bit of code I'm having trouble with:

Code: Select all
// CHROME CAST INIT
      cast.receiver.logger.setLevelValue(0);
      window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
      console.log('Starting Receiver Manager');
      
      // handler for the 'ready' event
      castReceiverManager.onReady = function(event) {
        console.log('Received Ready event: ' + JSON.stringify(event.data));
        window.castReceiverManager.setApplicationState("Application status is ready...");
        console.log("Application status is ready...");
      };
      
      console.log('COMPLETE:  Receiver Manager');
      
      
      // handler for 'senderconnected' event
      castReceiverManager.onSenderConnected = function(event) {
         console.log('Received Sender Connected event: ' + event.data);
         console.log(window.castReceiverManager.getSender(event.data).userAgent);

      };
      
      
      // handler for 'senderdisconnected' event
      castReceiverManager.onSenderDisconnected = function(event) {
         console.log('Received Sender Disconnected event: ' + event.data);
        if (window.castReceiverManager.getSenders().length == 0) {
         window.close();
        }
      };
            
      
      // handler for 'systemvolumechanged' event
      //castReceiverManager.onSystemVolumeChanged = function(event) {
      // console.log('Received System Volume Changed event: ' + event.data['level'] + ' ' +
      //      event.data['muted']);
      //};
      
      // create a CastMessageBus to handle messages for a custom namespace
      window.messageBus =
        window.castReceiverManager.getCastMessageBus(
           'urn:x-cast:com.google.cast.sample.helloworld');
          
      // handler for the CastMessageBus message event
      window.messageBus.onMessage = function(event) {
         console.log('Message [' + event.senderId + ']: ' + event.data);
         
         window.messageBus.send(event.senderId, event.data);
       
       
      }
      // initialize the CastReceiverManager with an application status message
      window.castReceiverManager.start({statusText: "Application is starting"});
      console.log('Receiver Manager started');
      
      
      console.log("-- Complete --");


The next question will be how do I make a player move forward? This is the code (from above) that is receiving messages from my Android phone:

Code: Select all
      // handler for the CastMessageBus message event
      window.messageBus.onMessage = function(event) {
         console.log('Message [' + event.senderId + ']: ' + event.data);
         
         window.messageBus.send(event.senderId, event.data);
       
                        // ON A NORMAL JAVASCRIPT PAGE I COULD DO THINGS LIKE THIS:
                       $("#player").css({left: "+="+event.data});
       
      }


Your help is appreciated :)
B
14
S
4
Posts: 25
Reputation: 968

Post » Sun Dec 07, 2014 1:13 am

Recently bought a chromecast and loving it. Great potential as a console for games.

Two things which might help: have you looked at scirra's google play plugin, which may well load an external library. Also here's an example for tic tac to, https://github.com/googlecast/Cast-TicTacToe-chrome
B
12
S
3
G
4
Posts: 57
Reputation: 3,186

Post » Sun Dec 07, 2014 7:28 am

u should use dependencies to load external libraries properly, its in the edittime file.
Last edited by QuaziGNRLnose on Sun Dec 07, 2014 7:32 pm, edited 1 time in total.
B
79
S
13
G
8
Posts: 1,976
Reputation: 9,947

Post » Sun Dec 07, 2014 2:16 pm

It's not your plugin's responsibility to implement any game logic like moving actual objects. Just expose the conditions/triggers via events, and let the user handle the event how they want (which might for example involve moving an object).
Scirra Founder
B
399
S
236
G
89
Posts: 24,519
Reputation: 195,351

Post » Mon Dec 08, 2014 7:20 am

@Ashley would it be possible to use Chrome-cast via C2
B
10
S
1
G
1
Posts: 63
Reputation: 840

Post » Mon Dec 08, 2014 2:41 pm

Hi Folks, I was able to get it working!

I was pretty close to making a native plugin for Construct 2. It recognized my app started and all that, but couldn't figure out how to have the Cast API listener always running.

So I reverted to my nasty hack.

After exporting the game, I simply edit index.html and add my external javascript API I wrote for Chromecast. Works like a friggin charm. I make heavy use of c2_callFunction("myFucntion", [1,2,3]);

The more I use Construct 2, the more I absolutely fall in love with this. I'm going to make SO MANY APPS. You guys rock.
B
14
S
4
Posts: 25
Reputation: 968

Post » Mon Dec 08, 2014 2:45 pm

@Ashley - Could you PM me? I'd like to discuss releasing a Chromecast support plugin to the community, if your team is interested.
B
14
S
4
Posts: 25
Reputation: 968

Post » Mon Dec 08, 2014 4:23 pm

@cybertron7 - use the Javascript SDK, it's fully documented and you are free to release it independently. You should also prefer to make a plugin and use the event system instead of using c2_callFunction.
Scirra Founder
B
399
S
236
G
89
Posts: 24,519
Reputation: 195,351

Post » Mon Dec 08, 2014 4:25 pm

Thanks Ashley,

Like I said, I'm half way with it, but I just can't figure out a few things. C2_callFunction works for now. It's easy enough to transfer my code in natively.

In time. Thanks,
B
14
S
4
Posts: 25
Reputation: 968

Post » Tue Feb 03, 2015 2:25 am

@cybertron7, any chance of you releasing a plugin for this? I'd love to create some projects using Google Cast. There are already some great games out there that leverage it, particularly board games like Apples To Apples and Cards Against Humanity.
B
19
S
6
G
2
Posts: 57
Reputation: 2,524

Next

Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests

cron