Dag Allen,
Ik haal 4 kleine stukjes uit een sprite-sheet met:
[JS]ctx.drawImage(img, 64, 8,8,8,80, 0,8,8);[/JS]
De vraag is hoe krijg ik de vier stukjes in een array en hoe zet ik de array als 1 plaatje op het canvas?
Dit is mijn test code tot nu toe:
(ook de drie regels van mijn TEST array code werken niet).
[JS]<!DOCTYPE html>
<html>
<body>
<p>Image to use:</p>
<img id="sprite-sheet" src="logi.bmp" alt="image" width="220" height="277">
<p>Canvas:</p>
<canvas id="myCanvas" width="512" height="380" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
document.getElementById("sprite-sheet").onload=function(){
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var img = document.getElementById("sprite-sheet");
Test = new array(); // test array code
Test[0] = "aap"; // test array code
document.write(Test); // test array code
document.write(StopLicht.src);
//rij x groen stoplicht
StopLicht= new array();
StopLicht[0].src = ctx.drawImage(img, 64, 8,8,8,80, 0,8,8);
StopLicht[1].src = ctx.drawImage(img, 72, 8,8,8,88, 0,8,8);
StopLicht[2].src = ctx.drawImage(img, 80, 8,8,8,80, 8,8,8);
StopLicht[3].src = ctx.drawImage(img, 88, 8,8,8,88, 8,8,8);
};
</script>
</body>
</html>[/JS]
Ik haal 4 kleine stukjes uit een sprite-sheet met:
[JS]ctx.drawImage(img, 64, 8,8,8,80, 0,8,8);[/JS]
De vraag is hoe krijg ik de vier stukjes in een array en hoe zet ik de array als 1 plaatje op het canvas?
Dit is mijn test code tot nu toe:
(ook de drie regels van mijn TEST array code werken niet).
[JS]<!DOCTYPE html>
<html>
<body>
<p>Image to use:</p>
<img id="sprite-sheet" src="logi.bmp" alt="image" width="220" height="277">
<p>Canvas:</p>
<canvas id="myCanvas" width="512" height="380" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
document.getElementById("sprite-sheet").onload=function(){
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var img = document.getElementById("sprite-sheet");
Test = new array(); // test array code
Test[0] = "aap"; // test array code
document.write(Test); // test array code
document.write(StopLicht.src);
//rij x groen stoplicht
StopLicht= new array();
StopLicht[0].src = ctx.drawImage(img, 64, 8,8,8,80, 0,8,8);
StopLicht[1].src = ctx.drawImage(img, 72, 8,8,8,88, 0,8,8);
StopLicht[2].src = ctx.drawImage(img, 80, 8,8,8,80, 8,8,8);
StopLicht[3].src = ctx.drawImage(img, 88, 8,8,8,88, 8,8,8);
};
</script>
</body>
</html>[/JS]