如何實際使用 HTML5 畫布的相機/視口?


對於視口使用,請使用 drawImage() 方法。

ctx.clearRect(0,0,game.width,game.height);
// a full background image
ctx.drawImage(background,cropLeft,cropTop,cropWidth,cropHeight,
0,0,viewWidth,viewHeight);

對於遊戲 −

var myGame = document.getElementById("game");
var myCtx= myGame.getContext("2d");
myCtx.clearRect(0,0,game.width,game.height);

// using drawImage() method
myCtx.drawImage(background,left,top,350,250,0,0,250,150);
myCtx.beginPath();
myCtx.arc(130,80,12,0,Math.PI*2,false);
myCtx.closePath();
myCtx.fill();
myCtx.stroke();

更新時間:2020-06-25

613 次瀏覽

開啟你的 職業生涯

完成課程可獲得認證

開始
廣告
© . All rights reserved.