Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
OutRed
GitHub Repository: OutRed/Cuphead-webgame
Path: blob/main/js/render.js
139 views
1
var canvas = document.getElementById('canvas');
2
var ctx = canvas.getContext('2d');
3
4
var sprPath='img/sprites/'
5
6
function flipX()
7
{
8
ctx.save();
9
ctx.scale(-1,1);
10
}
11
12
function flipY()
13
{
14
ctx.save();
15
ctx.scale(1,-1);
16
}
17
18
//Creating an image with taking a path to draw
19
function makeImage(path, x=0, y=0, width, height, flipSide=' ')
20
{
21
var img = new Image();
22
img.src = path;
23
24
25
if(flipSide == 'x')
26
{
27
x = -x - width;
28
flipX();
29
}
30
else if(flipSide == 'y')
31
{
32
y = -y - height;
33
flipY();
34
}
35
36
37
ctx.drawImage(img, x, y,width,height);
38
ctx.restore();
39
}
40
41
function checkImage(path)
42
{
43
var img = new Image();
44
img.src = path;
45
46
img.onload = function()
47
{
48
return true;
49
}
50
51
img.onerror = function()
52
{
53
return false;
54
}
55
}
56
57