-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHTML5 - Beginners - offscreenCanvas.html
52 lines (45 loc) · 1.23 KB
/
HTML5 - Beginners - offscreenCanvas.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<style>
#myCanvas {touch-action: none;
-webkit-touch-callout:none;
-webkit-user-select:none;
-khtml-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
-webkit-tap-highlight-color:rgba(0,0,0,0);
}
</style>
</head>
<body bgcolor="black">
<canvas id="myCanvas" width="320" height="240" style="border:0px solid #d3d3d3;">
Use different browser.
</canvas>
<script>
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var offscreenCanvas = document.createElement("canvas");
var ctx2 = offscreenCanvas.getContext("2d")
doGameLoop()
window.requestAnimationFrame(doGameLoop);
function doGameLoop(){
myCanvas.width = window.innerWidth-32;
myCanvas.height = window.innerHeight-32;
// offscreen canvas
offscreenCanvas.width=window.innerWidth-32;
offscreenCanvas.height=window.innerHeight-32;
ctx2.fillStyle="#FFFF00";
ctx2.fillRect(0,0,320,400);
//cls(0);
ctx.fillStyle="#1111FF";
ctx.fillRect(0,0,window.innerWidth,window.innerHeight);
ctx.drawImage(offscreenCanvas, 0, 0);
window.requestAnimationFrame(doGameLoop);
}
</script>
</body>
</html>