HTML and CSS Reference
In-Depth Information
}
iif ( keyPressList [ 37 ] == true
true ) {
//rotate counterclockwise
rotation -= rotationalVelocity ;
}
iif ( keyPressList [ 39 ] == true
true ) {
//rotate clockwise
rotation += rotationalVelocity ;;
}
Let's add this code to our current set of rotation examples and test it out. We have made some
major changes, so Example 8-8 presents the entire HTML file once again.
Example 8-8. Controlling the player ship
<!doctype html>
<html
<html lang= "en" >
<head>
<head>
<meta
<meta charset= "UTF-8" >
<title>
<title> CH8EX8: Ship Turn With Keys </title>
</title>
< script type = "text/javascript" >
window . addEventListener ( 'load' , eventWindowLoaded , false
false );
function
function eventWindowLoaded () {
canvasApp ();
}
function
function canvasApp (){
var
var theCanvas = document . getElementById ( "canvas" );
iif ( ! theCanvas || ! theCanvas . getContext ) {
return
return ;
}
var
var context = theCanvas . getContext ( "2d" );
iif ( ! context ) {
return
return ;
}
//canvasApp level variables
var
var rotation = 0 ;
var
var x = 50 ;
Search WWH ::




Custom Search