forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
motion lock - vertical.js
37 lines (22 loc) · 1.04 KB
/
motion lock - vertical.js
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
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render });
function preload() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.load.image('sprite', 'assets/sprites/darkwing_crazy.png');
}
var sprite;
function create() {
game.stage.backgroundColor = 'rgb(85,85,85)';
sprite = game.add.sprite(200, 200, 'sprite');
// Enable Input detection. Sprites have this disabled by default,
// so you have to start it if you want to interact with them.
sprite.inputEnabled = true;
// This allows you to drag the sprite. The parameter controls if you drag from the position you touched it (false)
// or if it will snap to the center (true)
sprite.input.enableDrag();
// This will lock the sprite so it can only be dragged vertically, not horizontally
sprite.input.allowHorizontalDrag = false;
}
function render() {
game.debug.renderInputInfo(32, 32);
game.debug.renderSpriteInputInfo(sprite, 300, 32);
}