mirror of
https://github.com/wassname/phaser.git
synced 2026-09-11 12:31:29 +08:00
Added Sprite.fixedToCamera, fixed Angular Velocity and Acceleration, fixed jittery Camera, added skipQuadTree flag and created lots more examples.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
$title = "Angular Acceleration";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
game.load.image('arrow', 'assets/sprites/arrow.png');
|
||||
}
|
||||
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#0072bc';
|
||||
|
||||
sprite = game.add.sprite(400, 300, 'arrow');
|
||||
sprite.anchor.setTo(0.5, 0.5);
|
||||
|
||||
// We'll set a lower max angular velocity here to keep it from going totally nuts
|
||||
sprite.body.maxAngular = 500;
|
||||
|
||||
// Apply a drag otherwise the sprite will just spin and never slow down
|
||||
sprite.body.angularDrag = 50;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
// Reset the acceleration
|
||||
sprite.body.angularAcceleration = 0;
|
||||
|
||||
// Apply acceleration if the left/right arrow keys are held down
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
sprite.body.angularAcceleration -= 200;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
sprite.body.angularAcceleration += 200;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteInfo(sprite, 32, 32);
|
||||
game.debug.renderText('angularVelocity: ' + sprite.body.angularVelocity, 32, 200);
|
||||
game.debug.renderText('angularAcceleration: ' + sprite.body.angularAcceleration, 32, 232);
|
||||
game.debug.renderText('angularDrag: ' + sprite.body.angularDrag, 32, 264);
|
||||
game.debug.renderText('deltaZ: ' + sprite.body.deltaZ(), 32, 296);
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
$title = "Angular Velocity";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
game.load.image('arrow', 'assets/sprites/arrow.png');
|
||||
}
|
||||
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#0072bc';
|
||||
|
||||
sprite = game.add.sprite(400, 300, 'arrow');
|
||||
sprite.anchor.setTo(0.5, 0.5);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
sprite.body.velocity.x = 0;
|
||||
sprite.body.velocity.y = 0;
|
||||
sprite.body.angularVelocity = 0;
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
sprite.body.angularVelocity = -200;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
sprite.body.angularVelocity = 200;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
sprite.body.velocity.copyFrom(game.physics.velocityFromAngle(sprite.angle, 300));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteInfo(sprite, 32, 32);
|
||||
game.debug.renderText('angularVelocity: ' + sprite.body.angularVelocity, 32, 200);
|
||||
game.debug.renderText('angularAcceleration: ' + sprite.body.angularAcceleration, 32, 232);
|
||||
game.debug.renderText('angularDrag: ' + sprite.body.angularDrag, 32, 264);
|
||||
game.debug.renderText('deltaZ: ' + sprite.body.deltaZ(), 32, 296);
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
||||
@@ -1,49 +1,41 @@
|
||||
<?php
|
||||
$title = "Motion";
|
||||
$title = "Mass Velocity Test";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update});
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('car', 'assets/sprites/car90.png');
|
||||
game.load.image('ship', 'assets/sprites/xenon2_ship.png');
|
||||
game.load.image('baddie', 'assets/sprites/space-baddie.png');
|
||||
|
||||
}
|
||||
|
||||
var car;
|
||||
var ship;
|
||||
var total;
|
||||
var aliens;
|
||||
|
||||
function create() {
|
||||
|
||||
aliens = [];
|
||||
aliens = game.add.group();
|
||||
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
var s = game.add.sprite(game.world.randomX, game.world.randomY, 'baddie');
|
||||
var s = aliens.create(game.world.randomX, game.world.randomY, 'baddie');
|
||||
s.name = 'alien' + s;
|
||||
s.body.collideWorldBounds = true;
|
||||
s.body.bounce.setTo(1, 1);
|
||||
s.body.bounce.setTo(0.8, 0.8);
|
||||
s.body.velocity.setTo(10 + Math.random() * 40, 10 + Math.random() * 40);
|
||||
aliens.push(s);
|
||||
}
|
||||
|
||||
car = game.add.sprite(400, 300, 'car');
|
||||
car.anchor.setTo(0.5, 0.5);
|
||||
car.body.collideWorldBounds = true;
|
||||
car.body.bounce.setTo(0.5, 0.5);
|
||||
car.body.bounce.setTo(0.8, 0.8);
|
||||
car.body.allowRotation = true;
|
||||
|
||||
ship = game.add.sprite(400, 400, 'ship');
|
||||
ship.body.collideWorldBounds = true;
|
||||
ship.body.bounce.setTo(0.5, 0.5);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
@@ -66,11 +58,15 @@
|
||||
car.body.velocity.copyFrom(game.physics.velocityFromAngle(car.angle, 300));
|
||||
}
|
||||
|
||||
game.physics.collide(aliens);
|
||||
game.physics.collide(car, aliens);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteInfo(car, 32, 32);
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
fuji = game.add.sprite(game.world.centerX, game.world.centerY, 'fuji');
|
||||
fuji.anchor.setTo(0, 0.5);
|
||||
fuji.angle = 34;
|
||||
// fuji.angle = 34;
|
||||
|
||||
b = new Phaser.Rectangle(fuji.center.x, fuji.center.y, fuji.width, fuji.height);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user