Revamping the examples area.

This commit is contained in:
photonstorm
2013-10-22 03:58:20 +01:00
parent 82df8c9f54
commit 07724e5001
380 changed files with 8619 additions and 10707 deletions
+29
View File
@@ -0,0 +1,29 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { 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.rotation = game.physics.accelerateToPointer(sprite, this.game.input.activePointer, 500, 500, 500);
}
function render() {
game.debug.renderSpriteInfo(sprite, 32, 32);
}
@@ -1,41 +0,0 @@
<?php
$title = "Accelerate to the Active Pointer";
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.rotation = game.physics.accelerateToPointer(sprite, this.game.input.activePointer, 500, 500, 500);
}
function render() {
game.debug.renderSpriteInfo(sprite, 32, 32);
}
</script>
<?php
require('../foot.php');
?>
+39
View File
@@ -0,0 +1,39 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('arrow', 'assets/sprites/longarrow.png');
game.load.image('ball', 'assets/sprites/pangball.png');
}
var arrow;
var target;
function create() {
game.stage.backgroundColor = '#0072bc';
arrow = game.add.sprite(200, 250, 'arrow');
arrow.anchor.setTo(0.1, 0.5);
target = game.add.sprite(600, 400, 'ball');
target.anchor.setTo(0.5, 0.5);
target.inputEnabled = true;
target.input.enableDrag(true);
}
function update() {
arrow.rotation = game.physics.angleBetween(arrow, target);
}
function render() {
game.debug.renderText("Drag the ball", 32, 32);
game.debug.renderSpriteInfo(arrow, 32, 100);
}
-51
View File
@@ -1,51 +0,0 @@
<?php
$title = "Angle between two Sprites";
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/longarrow.png');
game.load.image('ball', 'assets/sprites/pangball.png');
}
var arrow;
var target;
function create() {
game.stage.backgroundColor = '#0072bc';
arrow = game.add.sprite(200, 250, 'arrow');
arrow.anchor.setTo(0.1, 0.5);
target = game.add.sprite(600, 400, 'ball');
target.anchor.setTo(0.5, 0.5);
target.inputEnabled = true;
target.input.enableDrag(true);
}
function update() {
arrow.rotation = game.physics.angleBetween(arrow, target);
}
function render() {
game.debug.renderText("Drag the ball", 32, 32);
game.debug.renderSpriteInfo(arrow, 32, 100);
}
</script>
<?php
require('../foot.php');
?>
+31
View File
@@ -0,0 +1,31 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { 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() {
// This will update the sprite.rotation so that it points to the currently active pointer
// On a Desktop that is the mouse, on mobile the most recent finger press.
sprite.rotation = game.physics.angleToPointer(sprite);
}
function render() {
game.debug.renderSpriteInfo(sprite, 32, 32);
}
-43
View File
@@ -1,43 +0,0 @@
<?php
$title = "Angle between Sprite and Active Pointer";
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() {
// This will update the sprite.rotation so that it points to the currently active pointer
// On a Desktop that is the mouse, on mobile the most recent finger press.
sprite.rotation = game.physics.angleToPointer(sprite);
}
function render() {
game.debug.renderSpriteInfo(sprite, 32, 32);
}
</script>
<?php
require('../foot.php');
?>
+50
View File
@@ -0,0 +1,50 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { 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);
}
-62
View File
@@ -1,62 +0,0 @@
<?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');
?>
+49
View File
@@ -0,0 +1,49 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { 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))
{
game.physics.velocityFromAngle(sprite.angle, 300, sprite.body.velocity);
}
}
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);
}
-61
View File
@@ -1,61 +0,0 @@
<?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))
{
game.physics.velocityFromAngle(sprite.angle, 300, sprite.body.velocity);
}
}
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');
?>
+63
View File
@@ -0,0 +1,63 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('car', 'assets/sprites/car90.png');
game.load.image('baddie', 'assets/sprites/space-baddie.png');
}
var car;
var aliens;
function create() {
aliens = game.add.group();
for (var i = 0; i < 50; i++)
{
var s = aliens.create(game.world.randomX, game.world.randomY, 'baddie');
s.name = 'alien' + s;
s.body.collideWorldBounds = true;
s.body.bounce.setTo(0.8, 0.8);
s.body.velocity.setTo(10 + Math.random() * 40, 10 + Math.random() * 40);
}
car = game.add.sprite(400, 300, 'car');
car.anchor.setTo(0.5, 0.5);
car.body.collideWorldBounds = true;
car.body.bounce.setTo(0.8, 0.8);
car.body.allowRotation = true;
}
function update() {
car.body.velocity.x = 0;
car.body.velocity.y = 0;
car.body.angularVelocity = 0;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
car.body.angularVelocity = -200;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
car.body.angularVelocity = 200;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
car.body.velocity.copyFrom(game.physics.velocityFromAngle(car.angle, 300));
}
game.physics.collide(car, aliens);
}
function render() {
game.debug.renderSpriteInfo(car, 32, 32);
}
-76
View File
@@ -1,76 +0,0 @@
<?php
$title = "Mass Velocity Test";
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('car', 'assets/sprites/car90.png');
game.load.image('baddie', 'assets/sprites/space-baddie.png');
}
var car;
var aliens;
function create() {
aliens = game.add.group();
for (var i = 0; i < 50; i++)
{
var s = aliens.create(game.world.randomX, game.world.randomY, 'baddie');
s.name = 'alien' + s;
s.body.collideWorldBounds = true;
s.body.bounce.setTo(0.8, 0.8);
s.body.velocity.setTo(10 + Math.random() * 40, 10 + Math.random() * 40);
}
car = game.add.sprite(400, 300, 'car');
car.anchor.setTo(0.5, 0.5);
car.body.collideWorldBounds = true;
car.body.bounce.setTo(0.8, 0.8);
car.body.allowRotation = true;
}
function update() {
car.body.velocity.x = 0;
car.body.velocity.y = 0;
car.body.angularVelocity = 0;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
car.body.angularVelocity = -200;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
car.body.angularVelocity = 200;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
car.body.velocity.copyFrom(game.physics.velocityFromAngle(car.angle, 300));
}
game.physics.collide(car, aliens);
}
function render() {
game.debug.renderSpriteInfo(car, 32, 32);
}
</script>
<?php
require('../foot.php');
?>
+37
View File
@@ -0,0 +1,37 @@
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
function preload() {
game.load.image('ball', 'assets/sprites/shinyball.png');
}
var balls;
function create() {
balls = game.add.group();
for (var i = 0; i < 50; i++)
{
balls.create(game.world.randomX, game.world.randomY, 'ball');
}
}
function update() {
if (game.input.mousePointer.isDown)
{
// First is the callback
// Second is the context in which the callback runs, in this case game.physics
// Third is the parameter the callback expects - it is always sent the Group child as the first parameter
balls.forEach(game.physics.moveToPointer, game.physics, false, 200);
}
else
{
balls.setAll('body.velocity.x', 0);
balls.setAll('body.velocity.y', 0);
}
}
-53
View File
@@ -1,53 +0,0 @@
<?php
$title = "Group moves towards object";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
function preload() {
game.load.image('ball', 'assets/sprites/shinyball.png');
}
var balls;
function create() {
balls = game.add.group();
for (var i = 0; i < 50; i++)
{
balls.create(game.world.randomX, game.world.randomY, 'ball');
}
}
function update() {
if (game.input.mousePointer.isDown)
{
// First is the callback
// Second is the context in which the callback runs, in this case game.physics
// Third is the parameter the callback expects - it is always sent the Group child as the first parameter
balls.forEach(game.physics.moveToPointer, game.physics, false, 200);
}
else
{
balls.setAll('body.velocity.x', 0);
balls.setAll('body.velocity.y', 0);
}
}
</script>
<?php
require('../foot.php');
?>
@@ -0,0 +1,41 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update });
function preload() {
game.load.image('arrow', 'assets/sprites/longarrow.png');
}
var sprite1;
var sprite2;
var sprite3;
var sprite4;
function create() {
game.stage.backgroundColor = '#363636';
sprite1 = game.add.sprite(150, 150, 'arrow');
sprite1.anchor.setTo(0.1, 0.5);
sprite2 = game.add.sprite(200, 500, 'arrow');
sprite2.anchor.setTo(0.1, 0.5);
sprite3 = game.add.sprite(400, 200, 'arrow');
sprite3.anchor.setTo(0.1, 0.5);
sprite4 = game.add.sprite(600, 400, 'arrow');
sprite4.anchor.setTo(0.1, 0.5);
}
function update() {
// This will update the sprite.rotation so that it points to the currently active pointer
// On a Desktop that is the mouse, on mobile the most recent finger press.
sprite1.rotation = game.physics.angleToPointer(sprite1);
sprite2.rotation = game.physics.angleToPointer(sprite2);
sprite3.rotation = game.physics.angleToPointer(sprite3);
sprite4.rotation = game.physics.angleToPointer(sprite4);
}
@@ -1,53 +0,0 @@
<?php
$title = "Angle between Multiple Sprites and Pointers";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update });
function preload() {
game.load.image('arrow', 'assets/sprites/longarrow.png');
}
var sprite1;
var sprite2;
var sprite3;
var sprite4;
function create() {
game.stage.backgroundColor = '#363636';
sprite1 = game.add.sprite(150, 150, 'arrow');
sprite1.anchor.setTo(0.1, 0.5);
sprite2 = game.add.sprite(200, 500, 'arrow');
sprite2.anchor.setTo(0.1, 0.5);
sprite3 = game.add.sprite(400, 200, 'arrow');
sprite3.anchor.setTo(0.1, 0.5);
sprite4 = game.add.sprite(600, 400, 'arrow');
sprite4.anchor.setTo(0.1, 0.5);
}
function update() {
// This will update the sprite.rotation so that it points to the currently active pointer
// On a Desktop that is the mouse, on mobile the most recent finger press.
sprite1.rotation = game.physics.angleToPointer(sprite1);
sprite2.rotation = game.physics.angleToPointer(sprite2);
sprite3.rotation = game.physics.angleToPointer(sprite3);
sprite4.rotation = game.physics.angleToPointer(sprite4);
}
</script>
<?php
require('../foot.php');
?>
@@ -0,0 +1,67 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('ship', 'assets/sprites/xenon2_ship.png');
game.load.image('baddie', 'assets/sprites/space-baddie.png');
}
var ship;
var aliens;
function create() {
aliens = game.add.group();
for (var i = 0; i < 50; i++)
{
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.velocity.setTo(10 + Math.random() * 40, 10 + Math.random() * 40);
}
ship = game.add.sprite(400, 400, 'ship');
ship.body.collideWorldBounds = true;
ship.body.bounce.setTo(1, 1);
}
function update() {
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
ship.body.velocity.x -= 2;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
ship.body.velocity.x += 2;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
ship.body.velocity.y -= 2;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
ship.body.velocity.y += 2;
}
game.physics.collide(ship, aliens);
}
function render() {
game.debug.renderQuadTree(game.physics.quadTree);
game.debug.renderRectangle(ship.body);
// game.debug.renderText('total: ' + total.length, 32, 50);
game.debug.renderText('up: ' + ship.body.touching.up, 32, 70);
game.debug.renderText('down: ' + ship.body.touching.down, 32, 90);
game.debug.renderText('left: ' + ship.body.touching.left, 32, 110);
game.debug.renderText('right: ' + ship.body.touching.right, 32, 130);
}
+90
View File
@@ -0,0 +1,90 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('ship', 'assets/sprites/xenon2_ship.png');
game.load.image('baddie', 'assets/sprites/space-baddie.png');
}
var ship;
var total;
var aliens;
function create() {
game.world.setBounds(0,0,2000, 2000);
aliens = [];
for (var i = 0; i < 1000; i++)
{
var s = game.add.sprite(game.world.randomX, game.world.randomY, 'baddie');
s.name = 'alien' + s;
s.body.collideWorldBounds = true;
s.body.bounce.setTo(1, 1);
s.body.velocity.setTo(10 + Math.random() * 10, 10 + Math.random() * 10);
aliens.push(s);
}
ship = game.add.sprite(400, 400, 'ship');
ship.body.collideWorldBounds = true;
ship.body.bounce.setTo(0.5, 0.5);
}
function update() {
for (var i = 0; i < aliens.length; i++)
{
aliens[i].alpha = 0.3;
}
total = game.physics.quadTree.retrieve(ship);
// Get the ships top-most ID. If the length of that ID is 1 then we can ignore every other result,
// it's simply not colliding with anything :)
for (var i = 0; i < total.length; i++)
{
total[i].sprite.alpha = 1;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
ship.body.velocity.x -= 2;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
ship.body.velocity.x += 2;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
ship.body.velocity.y -= 2;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
ship.body.velocity.y += 2;
}
}
function render() {
for (var i = 0; i < aliens.length; i++)
{
// game.debug.renderRectangle(aliens[i].bounds);
}
game.debug.renderText(total.length, 32, 32);
game.debug.renderQuadTree(game.physics.quadTree);
// game.debug.renderRectangle(ship);
game.debug.renderText('Index: ' + ship.body.quadTreeIndex, 32, 80);
for (var i = 0; i < ship.body.quadTreeIDs.length; i++)
{
game.debug.renderText('ID: ' + ship.body.quadTreeIDs[i], 32, 100 + (i * 20));
}
}
+63
View File
@@ -0,0 +1,63 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('arrow', 'assets/sprites/arrow.png');
game.load.image('bullet', 'assets/sprites/purple_ball.png');
}
var sprite;
var bullets;
var fireRate = 100;
var nextFire = 0;
function create() {
game.stage.backgroundColor = '#313131';
bullets = game.add.group();
bullets.createMultiple(50, 'bullet');
bullets.setAll('anchor.x', 0.5);
bullets.setAll('anchor.y', 0.5);
bullets.setAll('outOfBoundsKill', true);
sprite = game.add.sprite(400, 300, 'arrow');
sprite.anchor.setTo(0.5, 0.5);
}
function update() {
sprite.rotation = game.physics.angleToPointer(sprite);
if (game.input.activePointer.isDown)
{
fire();
}
}
function fire() {
if (game.time.now > nextFire && bullets.countDead() > 0)
{
nextFire = game.time.now + fireRate;
var bullet = bullets.getFirstDead();
bullet.reset(sprite.x, sprite.y);
bullet.rotation = game.physics.moveToPointer(bullet, 300);
}
}
function render() {
game.debug.renderText('Active Bullets: ' + bullets.countLiving() + ' / ' + bullets.total, 32, 32);
game.debug.renderSpriteInfo(sprite, 32, 450);
}
-75
View File
@@ -1,75 +0,0 @@
<?php
$title = "Shoot the Pointer";
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');
game.load.image('bullet', 'assets/sprites/purple_ball.png');
}
var sprite;
var bullets;
var fireRate = 100;
var nextFire = 0;
function create() {
game.stage.backgroundColor = '#313131';
bullets = game.add.group();
bullets.createMultiple(50, 'bullet');
bullets.setAll('anchor.x', 0.5);
bullets.setAll('anchor.y', 0.5);
bullets.setAll('outOfBoundsKill', true);
sprite = game.add.sprite(400, 300, 'arrow');
sprite.anchor.setTo(0.5, 0.5);
}
function update() {
sprite.rotation = game.physics.angleToPointer(sprite);
if (game.input.activePointer.isDown)
{
fire();
}
}
function fire() {
if (game.time.now > nextFire && bullets.countDead() > 0)
{
nextFire = game.time.now + fireRate;
var bullet = bullets.getFirstDead();
bullet.reset(sprite.x, sprite.y);
bullet.rotation = game.physics.moveToPointer(bullet, 300);
}
}
function render() {
game.debug.renderText('Active Bullets: ' + bullets.countLiving() + ' / ' + bullets.total, 32, 32);
game.debug.renderSpriteInfo(sprite, 32, 450);
}
</script>
<?php
require('../foot.php');
?>
+46
View File
@@ -0,0 +1,46 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('fuji', 'assets/pics/atari_fujilogo.png');
}
var fuji;
var b;
function create() {
game.stage.backgroundColor = 'rgb(0,0,100)';
fuji = game.add.sprite(game.world.centerX, game.world.centerY, 'fuji');
fuji.anchor.setTo(0, 0.5);
// fuji.angle = 34;
b = new Phaser.Rectangle(fuji.center.x, fuji.center.y, fuji.width, fuji.height);
//Remember that the sprite is rotating around its anchor
game.add.tween(fuji).to({ angle: 360 }, 20000, Phaser.Easing.Linear.None, true, 0, true);
}
function update() {
if (game.input.activePointer.justPressed())
{
fuji.centerOn(game.input.x, game.input.y);
}
b.x = fuji.center.x - fuji.halfWidth;
b.y = fuji.center.y - fuji.halfHeight;
}
function render() {
//Phaser.DebugUtils.renderSpriteWorldViewBounds(fuji);
//Phaser.DebugUtils.renderSpriteBounds(fuji);
game.debug.renderSpriteCorners(fuji);
//Phaser.DebugUtils.renderSpriteWorldView(fuji, 32, 32);
game.debug.renderRectangle(b, 'rgba(0,20,91,1)');
}
-62
View File
@@ -1,62 +0,0 @@
<?php
$title = "Motion";
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('fuji', 'assets/pics/atari_fujilogo.png');
}
var fuji,
b;
function create() {
game.stage.backgroundColor = 'rgb(0,0,100)';
fuji = game.add.sprite(game.world.centerX, game.world.centerY, 'fuji');
fuji.anchor.setTo(0, 0.5);
// fuji.angle = 34;
b = new Phaser.Rectangle(fuji.center.x, fuji.center.y, fuji.width, fuji.height);
//Remember that the sprite is rotating around its anchor
game.add.tween(fuji).to({ angle: 360 }, 20000, Phaser.Easing.Linear.None, true, 0, true);
}
function update() {
if (game.input.activePointer.justPressed()){
fuji.centerOn(game.input.x, game.input.y);
}
b.x = fuji.center.x - fuji.halfWidth;
b.y = fuji.center.y - fuji.halfHeight;
}
function render() {
//Phaser.DebugUtils.renderSpriteWorldViewBounds(fuji);
//Phaser.DebugUtils.renderSpriteBounds(fuji);
game.debug.renderSpriteCorners(fuji);
//Phaser.DebugUtils.renderSpriteWorldView(fuji, 32, 32);
game.debug.renderRectangle(b, 'rgba(0,20,91,1)');
}
</script>
<?php
require('../foot.php');
?>