forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prismatic Constraint done. That's all of them! jshint time.
- Loading branch information
1 parent
87684bb
commit c3f687e
Showing
6 changed files
with
220 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update }); | ||
|
||
function preload() { | ||
|
||
game.load.image('vu', 'assets/sprites/vu.png'); | ||
game.load.image('ball', 'assets/sprites/arrow.png'); | ||
game.load.image('sky', 'assets/skies/cavern2.png'); | ||
|
||
} | ||
|
||
var sprite; | ||
var cursors; | ||
|
||
function create() { | ||
|
||
game.add.image(0, 0, 'sky'); | ||
|
||
// Enable p2 physics | ||
game.physics.startSystem(Phaser.Physics.P2JS); | ||
|
||
// Add 2 sprites which we'll join with a constraint | ||
sprite = game.add.sprite(400, 200, 'ball'); | ||
|
||
var vu1 = game.add.sprite(400, 300, 'vu'); | ||
|
||
game.physics.p2.enable([sprite, vu1]); | ||
|
||
// Lock the two bodies together. The [0, 50] sets the distance apart (y: 80) | ||
var constraint = game.physics.p2.createLockConstraint(sprite, vu1, [0, 80], 0); | ||
|
||
text = game.add.text(20, 20, 'move with arrow keys', { fill: '#ffffff' }); | ||
|
||
cursors = game.input.keyboard.createCursorKeys(); | ||
|
||
} | ||
|
||
function update() { | ||
|
||
if (cursors.left.isDown) | ||
{ | ||
sprite.body.moveLeft(100); | ||
} | ||
else if (cursors.right.isDown) | ||
{ | ||
sprite.body.moveRight(100); | ||
} | ||
|
||
if (cursors.up.isDown) | ||
{ | ||
sprite.body.moveUp(100); | ||
} | ||
else if (cursors.down.isDown) | ||
{ | ||
sprite.body.moveDown(100); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update }); | ||
|
||
function preload() { | ||
|
||
game.load.image('atari', 'assets/sprites/atari800xl.png'); | ||
game.load.image('lift', 'assets/sprites/flectrum.png'); | ||
game.load.image('sky', 'assets/skies/cavern2.png'); | ||
|
||
} | ||
|
||
var sprite; | ||
var vu1; | ||
var cursors; | ||
|
||
function create() { | ||
|
||
game.add.image(0, 0, 'sky'); | ||
|
||
// Enable p2 physics | ||
game.physics.startSystem(Phaser.Physics.P2JS); | ||
|
||
// Add 2 sprites which we'll join with a constraint | ||
sprite = game.add.sprite(200, 400, 'atari'); | ||
|
||
vu1 = game.add.sprite(400, 400, 'lift'); | ||
|
||
game.physics.p2.enable([sprite, vu1]); | ||
|
||
sprite.body.fixedRotation = true; | ||
vu1.body.fixedRotation = true; | ||
|
||
var constraint = game.physics.p2.createPrismaticConstraint(sprite, vu1, false, [150, 0], [-15, 0], [0, 1]); | ||
|
||
// You can also set limits: | ||
/* | ||
constraint.upperLimitEnabled = true; | ||
constraint.upperLimit = game.physics.p2.pxm(0.5); | ||
constraint.lowerLimitEnabled = true; | ||
constraint.lowerLimit = game.physics.p2.pxm(-0.5); | ||
*/ | ||
|
||
text = game.add.text(20, 20, 'move with arrow keys', { fill: '#ffffff' }); | ||
|
||
cursors = game.input.keyboard.createCursorKeys(); | ||
|
||
} | ||
|
||
function update() { | ||
|
||
sprite.body.setZeroVelocity(); | ||
vu1.body.setZeroVelocity(); | ||
|
||
if (cursors.left.isDown) | ||
{ | ||
sprite.body.moveLeft(200); | ||
} | ||
else if (cursors.right.isDown) | ||
{ | ||
sprite.body.moveRight(200); | ||
} | ||
|
||
if (cursors.up.isDown) | ||
{ | ||
vu1.body.moveUp(200); | ||
} | ||
else if (cursors.down.isDown) | ||
{ | ||
vu1.body.moveDown(200); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters