June 2015
Beginner
354 pages
8h 23m
English
Carry out the following steps to take the keyboard input:
box2dcargame.js JavaScript file in a text editor.keydown event handler at the beginning of the code. This listens to the right arrow key and the left arrow key to apply force in different directions:$(document).keydown(function(e){ switch(e.keyCode) { case 39: // right arrow key to apply force towards right var force = new b2Vec2(100, 0); carGame.car.ApplyForce(force, carGame.car.GetWorldCenter()); return false; break; case 37: // left arrow key to apply force towards left var force = new b2Vec2(-100, 0); carGame.car.ApplyForce(force, carGame.car.GetWorldCenter()); return false; break; ...Read now
Unlock full access