こんにちは私は3つのjavascriptファイルを持っています:Game.js、Player.js、Drawable.js。Game.jsで、オブジェクト_playerを作成します。これは、Drawableであり、それよりもPlayerです。これは、_playerがPlayerオブジェクト、つまりDrawableを拡張するクラスであることを意味します。
Drawable.js
function Drawable(x, y, src)
{
this.x = x;
this.y = y;
this.img = new Image();
this.img.src = src;
this.width = this.img.width;
this.height = this.img.height;
this.draw = function(canvas)
{
canvas.drawImage(this.img,this.x, this.y);
}
this.midpoint = function()
{
return {
x: this.x + this.width/2,
y: this.y + this.height/2};
}
}
}
Player.js
function Player()
{
this.moveLeft = function()
{
this.x -= 3;
}
this.moveRight = function()
{
this.x += 3;
}
this.moveUp = function()
{
this.y -= 3;
}
this.moveDown = function()
{
this.y += 3;
}
}
Game.js
var _player;
_player = new Player();
_player.draw(...);
_player.moveLeft();
...
...
これが私がやりたいことです。Player.prototype =newDrawable;を配置しようとしました。しかし、それは機能しません。どのようにできるのか?