April 2013
Beginner
750 pages
20h 21m
English
Example 9-3 shows the full code listing for the Fine Scrolling example.
Notice that this code adds in the colBuffer and rowBuffer variables as well as the matrix
transformation secret that performs the actual smooth fine
scrolling.
Example 9-3. Fine scrolling
<!doctype html><htmllang="en"><head><metacharset="UTF-8"><title>CH9 EX4 Scrolling Test 2 fine scrolling</title>
<scriptsrc="modernizr.js"></script><scripttype="text/javascript">window.addEventListener('load',eventWindowLoaded,false);functioneventWindowLoaded(){canvasApp();}</script><scriptlanguage="Javascript">functioncanvasSupport(){returnModernizr.canvas;}functioncanvasApp(){if(!canvasSupport()){return;}else{vartheCanvas=document.getElementById('canvas');varcontext=theCanvas.getContext('2d');}document.onkeydown=function(e){e=e?e:window.event;keyPressList[e.keyCode]=true;}document.onkeyup=function(e){//document.body.onkeyup=function(e){e=e?e:window.event;keyPressList[e.keyCode]=false;};//key pressesvarkeyPressList=[];//imagesvartileSheet=newImage();tileSheet.src="scrolling_tiles.png";//mapdatavarworld={};//cameravarcamera={};//key pressesvarkeyPressList={};varrowBuffer=1;varcolBuffer=1;varscrollRate=4;functioninit(){world.cols=15;world.rows=15;world.tileWidth=32;world.tileHeight=32;world.height=world.rows*world.tileHeight;world.width=world.cols*world.tileWidth;camera.height=theCanvas.height;camera.width
Read now
Unlock full access