forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphysics-motion.js
More file actions
82 lines (51 loc) · 1.73 KB
/
Copy pathphysics-motion.js
File metadata and controls
82 lines (51 loc) · 1.73 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
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('chunk', 'assets/sprites/chunk.png');
game.load.image('arrow', 'assets/sprites/asteroids_ship.png');
}
var sprite;
var bmd;
function create() {
game.stage.backgroundColor = '#124184';
bmd = game.add.bitmapData(800, 600);
bmd.fillStyle('#ffffff');
var bg = game.add.sprite(0, 0, bmd);
bg.body.moves = false;
game.physics.gravity.y = 100;
// sprite = game.add.sprite(732, 0, 'chunk');
// sprite = game.add.sprite(32, 450, 'chunk');
sprite = game.add.sprite(32, 450, 'arrow');
sprite.anchor.setTo(0.5, 0.5);
sprite.body.collideWorldBounds = true;
// sprite.body.bounce.setTo(0.5, 0.5);
sprite.body.bounce.setTo(0.8, 0.8);
//sprite.body.drag.setTo(0, -20);
// sprite.body.drag.setTo(10, 10);
sprite.body.friction = 0.1;
// sprite.body.sleepMin.setTo(-50, -20);
// sprite.body.sleepMax.setTo(50, 20);
// sprite.body.sleepDuration = 1000;
sprite.body.sleepMin.setTo(-5, -5);
sprite.body.sleepMax.setTo(5, 5);
sprite.body.sleepDuration = 500;
// sprite.body.canSleep = false;
game.input.onDown.add(launch, this);
}
function launch() {
// up and to the right
sprite.body.velocity.setTo(200, -300);
// sprite.body.velocity.setTo(-100, 300);
// sprite.body.gravity.setTo(0, -100);
// sprite.body.gravity.setTo(0, -100);
}
function update() {
sprite.rotation = sprite.body.angle;
// console.log(sprite.body.velocity.x);
bmd.fillStyle('#ffffff');
bmd.fillRect(sprite.x, sprite.y, 2, 2);
// bmd.fillStyle('#ff0000');
// bmd.fillRect(sprite.body.x, sprite.body.y, 2, 2);
}
function render() {
game.debug.renderBodyInfo(sprite, 16, 24);
}