Контекст не определен, JavaScript
function moveCamera() {
var canvas_holder = document.getElementById("game");
var context = canvas_holder.getContext("2d");
// camera code
// START
// Viewport height
var eye = $("#container").height();
// canvas height
var can_height = $("#canvas").height();
// Initial pos. of car. Multiplied by 30 to convert it into pixels.
// CHECK BETTER FOR CONVERTION
var car_pos = (car.GetWorldCenter().y)*30;
var half_eye = (eye/2);
// Initial Settings of camera
if ((car_pos > half_eye) && (can_height - car_pos) > half_eye){
context.translate(-(car_pos-half_eye),0);
} else if ((can_height - car_pos) < half_eye){
context.translate(-(can_height - eye), 0);
}
var pos = new Array();
var length;
// initial position of object is stored
pos[0] = (car.GetWorldCenter().y)*30;
//move camera
//vector is defined which will store the current y-coordinate
var p = new b2Vec2();
p = (car.GetWorldCenter().y)*30;
pos.push(p);
var length = pos.length;
// in pexels. finds out the distance moved in one timestep
var s = (pos[length-1]-pos[length-2]);
// checks if object is not in eye/2. Thus can be translated
if ((half_eye < (can_height - p)) && (p > half_eye)){
// canvas is translated
context.translate(-s,0);
}
}
поэтому у меня есть код выше, и я получаю справочный контекст ошибки не определен. это почему? Я имею в виду, я написал:
var canvas_holder = document.getElementById("game");
var context = canvas_holder.getContext("2d");
но похоже это не работает... почему? что мне не хватает? Может ли быть так, что.getContext не написан правильно?