-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
155 lines (132 loc) · 4.34 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="./bundle/arcade-physics.min.js"></script>
<script src="https://pixijs.download/v6.3.1/pixi.min.js"></script>
</head>
<body>
<style>
html {
background: #2c3349;
}
body {
font-family: Arial, Helvetica, sans-serif;
color: #f8f8f2;
text-align: center;
margin-bottom: 5em;
}
h2 {
margin-top: 2em;
}
#wrapper {
width: 100%;
}
canvas {
margin: 0 auto;
max-width: 100%;
display: block;
background: #0c0e14;
margin-bottom: 3em;
}
</style>
<h1>Arcade Physics<br /><small>(without Phaser)</small></h1>
<div style="margin-bottom: 8px">
<a style="text-decoration: none" href="https://github.com/yandeu/arcade-physics/actions/workflows/main.yml">
<img src="https://github.com/yandeu/arcade-physics/actions/workflows/main.yml/badge.svg" alt="CI" />
</a>
<a style="text-decoration: none" href="https://github.com/yandeu/arcade-physics/tree/gh-pages/bundle">
<img
src="https://badgen.net/badgesize/gzip/yandeu/arcade-physics/gh-pages/bundle/arcade-physics.min.js"
alt="gzip size"
/>
</a>
<a style="text-decoration: none" href="https://www.npmjs.com/package/arcade-physics">
<img src="https://img.shields.io/npm/v/arcade-physics" alt="version" />
</a>
<a style="text-decoration: none" href="https://codecov.io/gh/yandeu/arcade-physics">
<img
src="https://codecov.io/gh/yandeu/arcade-physics/branch/main/graph/badge.svg?token=7LZVKzgHUT"
alt="codecov"
/>
</a>
</div>
<div id="wrapper">
<h2>Debug Physics</h2>
<canvas id="myCanvas" width="800" height="450"></canvas>
<h2>Use Physics with PixiJS</h2>
</div>
<script>
const { ArcadePhysics } = PHYSICS
var canvas = document.getElementById('myCanvas')
var ctx = canvas.getContext('2d')
const config = {
width: 800,
height: 450,
gravity: {
x: 0,
y: 300
}
}
// physics
const physics = new ArcadePhysics(config)
// box
const box = physics.add.body(20, 20, 64, 64)
box.setVelocityX(20)
box.setBounce(0.6)
box.setCollideWorldBounds(true)
// ball
const ball = physics.add.body(206, 20)
ball.setCircle(32)
ball.setBounce(0.8)
ball.setCollideWorldBounds(true)
// platform
const platform = physics.add.staticBody(60, 350, 160, 32)
// colliders
physics.add.collider(box, ball)
physics.add.collider(box, platform)
physics.add.collider(ball, platform)
let tick = 0
const update = () => {
physics.world.update(tick * 1000, 1000 / 60)
physics.world.postUpdate(tick * 1000, 1000 / 60)
tick++
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height)
// draw debug
physics.world.bodies.forEach(b => {
b.drawDebug(ctx)
})
physics.world.staticBodies.forEach(b => {
b.drawDebug(ctx)
})
requestAnimationFrame(update)
}
requestAnimationFrame(update)
</script>
<script type="module">
const app = new PIXI.Application({ width: 800, height: 450 })
const wrapper = document.getElementById('wrapper')
wrapper.appendChild(app.view)
const pixi_box = PIXI.Sprite.from('demo/box.png')
const pixi_ball = PIXI.Sprite.from('demo/ball.png')
const pixi_platform = PIXI.Sprite.from('demo/platform.png')
/**
* Cartoon jungle vector created by brgfx (https://www.freepik.com/brgfx)
* https://www.freepik.com/vectors/cartoon-jungle
*/
const pixi_background = PIXI.Sprite.from('demo/background.jpg')
app.stage.addChild(pixi_background, pixi_box, pixi_ball, pixi_platform)
app.ticker.add(delta => {
pixi_box.x = box.x
pixi_box.y = box.y
pixi_ball.x = ball.x
pixi_ball.y = ball.y
pixi_platform.x = platform.x
pixi_platform.y = platform.y
})
</script>
</body>
</html>