forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug physics.js
More file actions
53 lines (38 loc) · 1.39 KB
/
Copy pathdebug physics.js
File metadata and controls
53 lines (38 loc) · 1.39 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
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update:update, render:render });
var sprite, otherSprite ;
var counter = 0 ;
var step = Math.PI * 2 / 360 ;
function preload() {
// Load images to use as the game sprites
game.load.image('sprite', 'assets/sprites/phaser2.png');
game.load.image('otherSprite', 'assets/sprites/phaser-dude.png');
}
function create() {
// Create sprite A and put it in the middle of the stage
sprite = game.add.sprite(0, 0, 'sprite');
sprite.alpha = 0.5 ;
sprite.x = game.width / 2 ;
sprite.anchor.x = sprite.anchor.y = 0.5 ;
// create sprite B
otherSprite = game.add.sprite(0, 0, 'otherSprite');
otherSprite.alpha = 0.5 ;
otherSprite.x = (game.width / 2) + 150 ;
otherSprite.y = (game.height / 2) + 150 ;
otherSprite.anchor.x = sprite.anchor.y = 0.5 ;
otherSprite.body.immovable = true ;
}
function update()
{
game.physics.collide( sprite, otherSprite ) ;
// Move sprite up and down smoothly for show
var tStep = Math.sin( counter ) ;
sprite.y = (game.height/2) + tStep * 30 ;
sprite.rotation += Phaser.Math.degToRad( 0.1 * tStep ) ;
counter += step ;
}
function render() {
// Physics
game.debug.renderSpriteBody(sprite);
game.debug.renderSpriteCollision(sprite, 32, 32);
game.debug.renderSpriteBody(otherSprite);
}