HTML and CSS Reference
In-Depth Information
return false;} // does not intersect
}
In our application, the player presses an arrow key and, based on that key, the next position of the token
is calculated. We call the intersect function to see if there would be an intersection of the token
(approximated as a circle) and a wall. If intersect returns true , the token is not moved. The checking
stops as soon as there is an intersection. This is a common technique for collision checking.
Using local storage
The Web was originally designed for files being downloaded from the server to the local, so-called client
computer for viewing, but with no permanent storage on the local computer. Over time, people and
organizations building web sites decided that some sort of local storage would be advantageous. So,
someone came up with the idea of using small files called cookies to keep track of things, such as user
IDs stored for the convenience of the user as well as the web site owner. The use of cookies, Flash's
shared objects, and now HTML5 local storage has grown considerably with the commercial Web. Unlike
the situation for the applications shown here, the user often does not know that information is being stored
and by whom, and for what purpose the information is accessed.
The localStorage facility of HTML5 is browser-specific. That is, a maze saved using Chrome is not
available to someone using FireFox.
Lets take a closer look at using local storage by examining a small application that saves date and time
information. Local storage and the Date function, introduced in Chapter 1, provide a way to store
date/time information. Think of local storage as a database in which strings of characters are stored, each
under a specific name. The name is called the key , the string itself is the value , and the system is called
key/value pairs. The fact that local storage just stores strings is a restriction, but the next section shows
how to work around it.
Figure 7-9 shows a screen shot from the opening screen of a simple date saving application.
Figure 7-9. A simple save date application
The user has three options: store information on the current date and time, retrieve the last information
saved, and remove the date information. Figure 7-10 shows what happens when clicking “Retrieve date
info” the very first time using this application (or after the date has been removed).
Figure 7-10. Data not yet saved or after removal
 
Search WWH ::




Custom Search