JavaScriptとHTML5を使用してアニメーションを理解しようとしています。 私はインターネットで調査した後、requestAnimationFrameが繰り返しメソッドを呼び出します。simple requestAnimationFrame not working JavaScript
私はプレーンを作成し、そのプレーンを対角線上に移動するメソッドを作成しました。しかし、それはアニメーションがないようです。
私はこれをかなり新しくしているので、私はそれほど概念を得ていないかもしれません。クロムとインターネットエクスプローラの両方で試してみたので、私のブラウザとは関係ないと思います。数ヶ月前に新しいノートパソコンとしてインストールしたので、最新のものにしてください。ここで
が私のメインクラスである、それはすべてのreleventコード含まれている必要があります
/*global window, document, alert, Vector, Moth, Matrix, Plane, SceneGraphNode*/
function onLoad() {
var mainCanvas, mainContext, planePosition, plane;
// this function will initialise our variables
function initialiseCanvasContext() {
// Find the canvas element using its id attribute.
mainCanvas = document.getElementById('mainCanvas');
// if it couldn't be found
if (!mainCanvas) {
// make a message box pop up with the error.
alert('Error: I cannot find the canvas element!');
return;
}
// Get the 2D canvas context.
mainContext = mainCanvas.getContext('2d');
if (!mainContext) {
alert('Error: failed to get context!');
return;
}
planePosition = new Vector(0, 0, 0);
plane = new Plane(planePosition);
}
function translate(pPosition) {
var matrix = Matrix.createTranslation(pPosition);
matrix.transform(mainContext);
}
function scale(pPosition) {
var matrix = Matrix.createScale(pPosition);
matrix.transform(mainContext);
}
function rotate(pPosition) {
var matrix = Matrix.createRotation(pPosition);
matrix.transform(mainContext);
}
function drawPlane() {
scaleVector = new Vector(0.25, 0.25, 0);
scale(scaleVector);
translate(new Vector(0, 0));
rotate(0);
plane.draw(mainContext);
}
function drawMoth() {
var moth, mothPosition;
mothPosition = new Vector(mainCanvas.width/2, mainCanvas.height/2, 0);
moth = new Moth(mothPosition);
moth.draw(mainContext);
}
function drawPlane() {
plane = new Plane(planePosition);
scale(new Vector(0.25, 0.25, 0));
plane.draw(mainContext);
}
function animatePlane() {
translate(planePosition.add(new Vector(100, 100, 0)));
drawPlane();
window.requestAnimationFrame(animatePlane);
}
initialiseCanvasContext();
drawMoth();
animatePlane();
}
window.addEventListener('load', onLoad, false);
をあなたはそれがすべての関連メソッドを参照するのに役立つだろうと思うなら、私に知らせてください。私は結果を添付しました。
関連するすべてのコードを含めるように質問を更新してください。 &これらの2つの関数はどこに呼び出されますか? –
こんにちは、今更新しました。ごめんなさい – lucycopp
あなたのコンソールに何かエラーがありますか? – balapa