オブジェクトが画像を描画しないという問題があります。画像の onload プロパティを draw 関数に設定しました。
//ctor
function Sprite(someargs,pContext)
this.setContext(pContext); //This could be the problem?
this.setX(px);
this.setY(py);
this.setTexture(pImagePath);
//I run this in the constructor
Sprite.prototype.setTexture = function(pImagePath){
this.texture = new Image();
this.texture.onload = this.draw();
this.texture.src = pImagePath;
};
Sprite.prototype.draw = function(){
this.getContext().drawImage(this.texture,this.getX(),this.getY(),100,100);
};
Sprite.prototype.setContext = function(pContext){
this.mContext = pContext;
};
実行時にエラーはありませんが、イメージはキャンバスに描画されません。上記のすべてのメソッドにアラートを設定しました。これらはすべて実行されています。
なぜそれが描かれていないのか、誰にもアイデアがありますか?
乾杯