Hello World AirConsole tutorial: your first AirConsole project
Talking about Javascript.
Learn cross platform HTML5 game development
Check my Gumroad page for commented source code, games and books.
airconsole
, then place two files inside it called screen.html
and controller.html
. The first will be the game screen, while the latter will be the controller screen.
This is the content of controller.html
:
<html>
<head>
<script type="text/javascript" src="https://www.airconsole.com/api/airconsole-1.4.0.js"></script>
<script type="text/javascript">
// creation of a new AirConsole instance
var airconsole = new AirConsole();
// function to be executed every 3 seconds
setInterval(function(){
// generating a random value
var value = Math.floor(Math.random() * 100);
// this is how we send a message to AirConsole main screen
airconsole.message(AirConsole.SCREEN, value);
// updating "value" h1 content to show on the controller the value we are sending
document.getElementById("value").innerHTML = "I am sending " + value;
}, 3000);
</script>
</head>
<body>
<h1 id = "value" style = "color:white;margin-top:150px"></h1>
</body>
</html>
screen.html
:
<html>
<head>
<script type="text/javascript" src="https://www.airconsole.com/api/airconsole-1.4.0.js"></script>
<script type="text/javascript">
// creation of an empty array
var deviceIds = [];
// creation of a new AirConsole instance
var airconsole = new AirConsole();
// this is the listener for incoming messages
airconsole.onMessage = function(deviceId, data) {
// checking if the deviceId is already in deviceIds vector, and if it's not...
if(deviceIds.indexOf(deviceId) == -1){
// pushing the device id
deviceIds.push(deviceId);
// adding a new h1 to the body
document.body.innerHTML += '<h1 style = "color:white" id = "dev' + deviceId + '"></h1>'
}
// updating the content of the proper h1 tag according to device id and received data
document.getElementById("dev" + deviceId).innerHTML = "I am receiving " + data + " from device " + deviceId;
};
</script>
</head>
<body>
</body>
</html>
http://www.airconsole.com/simulator/#<path_to_airconsole_directory>
which in my case was http://www.airconsole.com/simulator/#http://localhost/airconsole/
but it may vary according to the name you gave to folder project and the path to your local server.
And that’s what I got:

Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.