1
我有這個簡單的代碼:JavaScript的OOP概念問題
// You can use either PIXI.WebGLRenderer or PIXI.CanvasRenderer
var renderer;
var stage;
var bunnyTexture;
var bunny;
var Game= {};
Game.Init = function() { };
Game.Init.prototype={
init:function(){
renderer= new PIXI.WebGLRenderer(800, 600);
document.body.appendChild(renderer.view);
stage= new PIXI.Stage;
bunnyTexture= PIXI.Texture.fromImage("img/ninja.png");
bunny= new PIXI.Sprite(bunnyTexture);
bunny.position.x = 400;
bunny.position.y = 300;
stage.addChild(bunny);
},
animate:function(){
bunny.rotation += 0.01;
renderer.render(stage);
requestAnimationFrame(this.animate);
}
}
requestAnimationFrame(Game.Init.animate);
我打電話像這樣的功能:
window.onload = function() { Game.Init(); };
一個JavaScript錯誤說:Argument 1 of Window.requestAnimationFrame is not an object.
我仍然得到相同的錯誤,你可以給我一個例子,我該如何解決我的錯誤,請 – Sora 2014-10-28 12:31:48