forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkey.php
More file actions
67 lines (45 loc) · 1.3 KB
/
Copy pathkey.php
File metadata and controls
67 lines (45 loc) · 1.3 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
<?php
$title = "Creating and using a Key object";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
function preload() {
game.load.image('phaser', 'assets/sprites/phaser-dude.png');
}
var sprite;
var upKey;
var downKey;
var leftKey;
var rightKey;
function create() {
game.stage.backgroundColor = '#736357';
sprite = game.add.sprite(300, 300, 'phaser');
// In this example we'll create 4 specific keys (up, down, left, right) and monitor them in our update function
upKey = game.input.keyboard.addKey(Phaser.Keyboard.UP);
downKey = game.input.keyboard.addKey(Phaser.Keyboard.DOWN);
leftKey = game.input.keyboard.addKey(Phaser.Keyboard.LEFT);
rightKey = game.input.keyboard.addKey(Phaser.Keyboard.RIGHT);
}
function update() {
if (upKey.isDown)
{
sprite.y--;
}
else if (downKey.isDown)
{
sprite.y++;
}
if (leftKey.isDown)
{
sprite.x--;
}
else if (rightKey.isDown)
{
sprite.x++;
}
}
</script>
<?php
require('../foot.php');
?>