Ich habe eine html5 Leinwand, die eine Schallwelle zeichnet. Ich habe den Hintergrund als Hintergrundbild festgelegt, möchte dieses Hintergrundbild jedoch wiederholen. Kann mir jemand sagen, wie ich dies tun würde und was brauche ich in meinen Code hinzuzufügen:HTML5 Leinwand Hintergrundbild wiederholen
var backgroundImage = new Image();
backgroundImage.src = 'http://www.samskirrow.com/client-kyra/images/main-bg.jpg';
var canvas;
var context;
function init(c) {
canvas = document.getElementById(c);
context = canvas.getContext("2d");
soundManager.onready(function() {
initSound(clientID, playlistUrl);
});
aniloop();
}
function aniloop() {
requestAnimFrame(aniloop);
drawWave();
}
function drawWave() {
var step = 10;
var scale = 60;
// clear
context.drawImage(backgroundImage, 0, 0);
// left wave
context.beginPath();
context.moveTo(0, 256);
for (var i = 0; i < 256; i++) {
context.lineTo(6 * i, 257 + waveLeft[i] * 80.);
}
context.lineWidth = 1;
context.strokeStyle = "#000";
context.stroke();
// right wave
context.beginPath();
context.moveTo(0, 256);
for (var i = 0; i < 256; i++) {
context.lineTo(6 * i, 256 + waveRight[i] * 80.);
}
context.lineWidth = 1;
context.strokeStyle = "#000";
context.stroke();
}
function updateWave(sound) {
waveLeft = sound.waveformData.left;
}
return {
init : init
};
})();
Sie diesen Code in Aktion hier sehen können: http://www.samskirrow.com/client-kyra
können Sie CSS nicht für Hintergrund wiederholen verwenden? –
@MuhammadShoaib: Nein, nicht für Bilder auf der Leinwand gezeichnet. – Cerbrus