mirror of
https://github.com/wassname/phaser.git
synced 2026-08-17 11:23:42 +08:00
Lots of fixes and updates to ArcadePhysics and Group, plus more examples.
This commit is contained in:
@@ -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