forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoving the camera.js
More file actions
52 lines (36 loc) · 1021 Bytes
/
Copy pathmoving the camera.js
File metadata and controls
52 lines (36 loc) · 1021 Bytes
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
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
}
var cursors;
function create() {
game.stage.backgroundColor = '#2d2d2d';
// Make our game world 2000x2000 pixels in size (the default is to match the game size)
game.world.setBounds(0, 0, 2000, 2000);
for (var i = 0; i < 150; i++)
{
game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
}
cursors = game.input.keyboard.createCursorKeys();
}
function update() {
if (cursors.up.isDown)
{
game.camera.y -= 4;
}
else if (cursors.down.isDown)
{
game.camera.y += 4;
}
if (cursors.left.isDown)
{
game.camera.x -= 4;
}
else if (cursors.right.isDown)
{
game.camera.x += 4;
}
}
function render() {
game.debug.renderCameraInfo(game.camera, 32, 32);
}