mirror of
https://github.com/wassname/phaser.git
synced 2026-07-19 11:26:26 +08:00
New 'thrust' demo. Added Body.moveLeft, moveRight, moveUp, moveDown, rotateLeft, rotateRight and thrust methods. Also hooked up force and created an asteroids style example.
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 913 B |
+9
-2
@@ -3,6 +3,7 @@ var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload:
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('backdrop', 'assets/pics/remember-me.jpg');
|
||||
game.load.image('box', 'assets/sprites/block.png');
|
||||
|
||||
}
|
||||
@@ -21,17 +22,23 @@ function px2p(v) {
|
||||
|
||||
function create() {
|
||||
|
||||
game.world.setBounds(0, 0, 1920, 1200);
|
||||
game.add.sprite(0, 0, 'backdrop');
|
||||
|
||||
box = game.add.sprite(200, 200, 'box');
|
||||
box.anchor.set(0.5);
|
||||
box.physicsEnabled = true;
|
||||
|
||||
box2 = game.add.sprite(400, 100, 'box');
|
||||
box2.anchor.set(0.5);
|
||||
box2 = game.add.sprite(400, 200, 'box');
|
||||
box2.anchor.set(0.5); // if using physics you nearly always need to anchor from the center like this unless you don't need rotation
|
||||
// box2.scale.set(2); // if you need to scale, do it BEFORE enabling physics. You can't do it at run-time.
|
||||
box2.physicsEnabled = true;
|
||||
|
||||
box2.body.setZeroDamping();
|
||||
box2.body.fixedRotation = true;
|
||||
|
||||
game.camera.follow(box2);
|
||||
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
|
||||
game.physics.defaultRestitution = 0.8;
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('backdrop', 'assets/pics/remember-me.jpg');
|
||||
game.load.image('ship', 'assets/sprites/thrust_ship2.png');
|
||||
|
||||
}
|
||||
|
||||
var ship;
|
||||
var cursors;
|
||||
|
||||
function p2px(v) {
|
||||
return v *= -20;
|
||||
}
|
||||
|
||||
function px2p(v) {
|
||||
return v * -0.05;
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
game.world.setBounds(0, 0, 1920, 1200);
|
||||
|
||||
var bg = game.add.sprite(0, 0, 'backdrop');
|
||||
bg.alpha = 0.2;
|
||||
|
||||
ship = game.add.sprite(200, 200, 'ship');
|
||||
ship.anchor.set(0.5);
|
||||
ship.physicsEnabled = true;
|
||||
|
||||
game.camera.follow(ship);
|
||||
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
|
||||
game.physics.defaultRestitution = 0.8;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (cursors.left.isDown)
|
||||
{
|
||||
ship.body.rotateLeft(100);
|
||||
}
|
||||
else if (cursors.right.isDown)
|
||||
{
|
||||
ship.body.rotateRight(100);
|
||||
}
|
||||
else
|
||||
{
|
||||
ship.body.setZeroRotation();
|
||||
}
|
||||
|
||||
if (cursors.up.isDown)
|
||||
{
|
||||
ship.body.thrust(400);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
// game.debug.renderText('x: ' + box2.body.velocity.x, 32, 32);
|
||||
// game.debug.renderText('y: ' + box2.body.velocity.y, 32, 64);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user