-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinventory.html
More file actions
122 lines (104 loc) · 2.6 KB
/
Copy pathinventory.html
File metadata and controls
122 lines (104 loc) · 2.6 KB
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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Making your first Phaser 3 Game - Part 1</title>
<script src="//cdn.jsdelivr.net/npm/phaser@3.11.0/dist/phaser.js"></script>
<style type="text/css">
body {
margin: 0;
}
</style>
</head>
<body>
<script type="text/javascript">
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#D2B48C',
physics: {
default: 'arcade',
arcade: {
debug: false
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
const tileCoordinates = [
{
x: 100,
y: 100
},
{
x: 200,
y: 100
},
{
x: 300,
y: 100
},
{
x: 100,
y: 200
},
{
x: 200,
y: 200
},
{
x: 300,
y: 200
}
]
const FRAMES = {
inventoryTile: 7,
upButton: 135,
downButton: 134,
activeUpButton: 148,
activeDownButton: 147,
}
var game = new Phaser.Game(config);
var inventoryTiles = [];
var upButton;
var downButton;
function preload ()
{
this.load.spritesheet('ui-assets', 'assets/ui-elements.png', { frameWidth: 64, frameHeight: 64, startFrame:0, endFrame: 153 });
}
function create ()
{
this.anims.create({
key: 'inventoryTile',
frames: [ { key: 'ui-assets', frame: 0 } ],
frameRate: 20
});
upButton = this.add.sprite(400, 100, 'ui-assets', FRAMES.upButton).setInteractive();
upButton.on('pointerdown', () => {
upButton.setFrame(FRAMES.activeUpButton);
});
upButton.on('pointerup', () => {
upButton.setFrame(FRAMES.upButton);
});
downButton = this.add.sprite(400, 200, 'ui-assets', FRAMES.downButton).setInteractive();
downButton.on('pointerdown', () => {
downButton.setFrame(FRAMES.activeDownButton);
});
downButton.on('pointerup', () => {
downButton.setFrame(FRAMES.downButton);
});
tileCoordinates.forEach(i => {
let tile = this.add.sprite(i.x, i.y, 'ui-assets', FRAMES.inventoryTile).setInteractive();
inventoryTiles.push(tile);
})
}
function update ()
{
}
</script>
</body>
</html>