mirror of
https://github.com/wassname/phaser.git
synced 2026-08-15 12:45:11 +08:00
Lots of fixes and updates to ArcadePhysics and Group, plus more examples.
This commit is contained in:
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 130 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 490 B |
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -5,29 +5,38 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', {create: create, render: render });
|
||||
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#454645';
|
||||
|
||||
// By default Phaser only starts 2 pointers (enough for 2 fingers at once)
|
||||
|
||||
// addPointer tells Phaser to add another pointer to Input, so here we are basically saying "allow up to 6 pointers + the mouse"
|
||||
|
||||
// Note: on iOS as soon as you use 6 fingers you'll active the minimise app gesture - and there's nothing we can do to stop that, sorry
|
||||
|
||||
game.input.addPointer();
|
||||
game.input.addPointer();
|
||||
game.input.addPointer();
|
||||
game.input.addPointer();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
// Just renders out the pointer data when you touch the canvas
|
||||
game.debug.renderPointer(game.input.mousePointer);
|
||||
game.debug.renderPointer(game.input.pointer1);
|
||||
game.debug.renderPointer(game.input.pointer2);
|
||||
game.debug.renderPointer(game.input.pointer3);
|
||||
game.debug.renderPointer(game.input.pointer4);
|
||||
game.debug.renderPointer(game.input.pointer5);
|
||||
game.debug.renderPointer(game.input.pointer6);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?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.angleBetweenPointer(sprite);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteInfo(sprite, 32, 32);
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
sprite.body.velocity.copyFrom(game.physics.velocityFromAngle(sprite.angle, 300));
|
||||
game.physics.velocityFromAngle(sprite.angle, 300, sprite.body.velocity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?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, render: render });
|
||||
|
||||
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.angleBetweenPointer(sprite1);
|
||||
sprite2.rotation = game.physics.angleBetweenPointer(sprite2);
|
||||
sprite3.rotation = game.physics.angleBetweenPointer(sprite3);
|
||||
sprite4.rotation = game.physics.angleBetweenPointer(sprite4);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
// game.debug.renderSpriteInfo(sprite1, 32, 32);
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
$title = "Shoot at the Mouse";
|
||||
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.angleBetweenPointer(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.moveTowardsPointer(bullet, 300);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderText('Active Bullets: ' + bullets.countLiving() + ' / ' + bullets.total, 32, 32);
|
||||
|
||||
game.debug.renderSpriteInfo(sprite, 32, 450);
|
||||
game.debug.renderSpriteCorners(sprite);
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
||||
Reference in New Issue
Block a user