3D Game Programming

(C. Jardin) #1
the DOM to make changes to web pages (change colors, show pop-up boxes).
When the browser has read a web page and converted it into the DOM, the
DOM is said to be “ready.” With on-dom-ready, we listen to the document:

// Wait until the web page is fully loaded
document.addEventListener("DOMContentLoaded",function() {
document.body.appendChild(renderer.domElement);
});

This trick goes in the JavaScript, not the web page, and takes advantage of
an important aspect of web pages: they like to shout about things that happen.
A lot of the time, no one and nothing is listening when the browser shouts.
But knowing that a browser does this gives us power.

In this case, we have the power to listen to one particular browser event:
DOMContentLoaded. When the browser loads all of the content a page needs, the
browser shouts to anybody who is interested. Here we tell that browser that
yes, we’re interested, and that when such an event happens, we should add
our 3D renderer to the page.

21.2 Free Websites


Earlier we noted that only publicly available web servers can serve up web
pages, images, JavaScript, and so on. Normally this will cost you some money.
But there are ways to get your web pages and JavaScript games publicly
available for free:


  • Tumblr^1

  • Blogger^2

  • WordPress^3


When You Might Need to Pay
We just talked about ways to get a public site without paying. Why
would you ever need to pay?

The answer is that you need to pay when your website needs to
store new information. If a website needs to keep track of users,
then you need to pay to have space to save that information. If a
website needs to remember players’ scores, then you’ll need to pay
for a place to keep that information.


  1. http://tumblr.com

  2. http://blogger.com

  3. http://www.wordpress.com


Chapter 21. Getting Code on the Web • 212


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf