2016-12-18 8 views
1

私が使用したイメージの長さ/幅はどのくらいですか? イメージが終了したときにイメージを繰り返すには、2番目のdrawImageで指定する必要があります。イメージの実際の長さを取得するJavaScriptファイル

function Background() { 
    this.speed = 2; // Redefine speed of the background for panning 
    // Implement abstract function 
    this.draw = function() { 
     // Pan background 
     //  this.x -= this.speed; 
     this.context.drawImage(imageRepository.background, this.x, this.y); 
     this.x -= this.speed; 
     // Draw another image at the top edge of the first image 
     this.context.drawImage(imageRepository.background, this.x, this.y); 
     //  // If the image scrolled off the screen, reset 
     //  if (this.x <= -this.background.naturalWidth) this.x = 0; 
    }; 
} 
+0

多くの研究がこのように進んでいるようには思われません – charlietfl

答えて

1

context.drawImageの最初の引数として渡されるイメージは、widthとheightプロパティを持つ必要があります。したがって、imageRepository.background.widthimageRepository.backgroundイメージの幅で、imageRepository.background.heightはその高さである必要があります。

+0

それは画像がどこから来るかによって異なります。私たちはOPのコードブロックでそれを見ることができないので、それがどのように作成されたのか分からないし、drawImageはnaturalWidthとnaturalHeightをデフォルトとして取るので、これらのプロパティを得る方が良い。 – Kaiido

関連する問題