Skip to content

Commit a52a34d

Browse files
committed
docs: add depth sort scene example
1 parent 50c31a9 commit a52a34d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

examples/scene/depthSortObjects.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Rect Sprite</title>
5+
<script src="../../kontra.js"></script>
6+
</head>
7+
<body>
8+
<canvas id="game" width="600" height="400" style="background: #333331"></canvas>
9+
<script id="code">
10+
// initialize the game and setup the canvas
11+
kontra.init();
12+
13+
// create the scene
14+
let scene = kontra.Scene({
15+
id: 'Game Scene',
16+
sortFunction: kontra.depthSort
17+
});
18+
19+
// create some sprites
20+
let colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];
21+
for (let i = 0; i < colors.length; i++) {
22+
scene.add(
23+
kontra.Sprite({
24+
x: 250 + i * 10,
25+
y: 200 - i * 10,
26+
width: 25,
27+
height: 50,
28+
color: colors[i]
29+
})
30+
);
31+
}
32+
33+
// render the scene
34+
scene.render();
35+
</script>
36+
<script src="../prism/codeOutput.js"></script>
37+
</body>
38+
</html>
File renamed without changes.

0 commit comments

Comments
 (0)