mirror of
https://github.com/wassname/phaser.git
synced 2026-07-04 17:20:31 +08:00
Lots of new examples and updates.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?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');
|
||||
?>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?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');
|
||||
?>
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
// 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);
|
||||
sprite.rotation = game.physics.angleToPointer(sprite);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
|
||||
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');
|
||||
@@ -39,16 +39,10 @@
|
||||
// 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);
|
||||
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,5 +1,5 @@
|
||||
<?php
|
||||
$title = "Shoot at the Mouse";
|
||||
$title = "Shoot the Pointer";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
@@ -8,8 +8,10 @@
|
||||
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;
|
||||
@@ -35,7 +37,7 @@
|
||||
|
||||
function update() {
|
||||
|
||||
sprite.rotation = game.physics.angleBetweenPointer(sprite);
|
||||
sprite.rotation = game.physics.angleToPointer(sprite);
|
||||
|
||||
if (game.input.activePointer.isDown)
|
||||
{
|
||||
@@ -54,8 +56,7 @@
|
||||
|
||||
bullet.reset(sprite.x, sprite.y);
|
||||
|
||||
bullet.rotation = game.physics.moveTowardsPointer(bullet, 300);
|
||||
|
||||
bullet.rotation = game.physics.moveToPointer(bullet, 300);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -63,9 +64,7 @@
|
||||
function render() {
|
||||
|
||||
game.debug.renderText('Active Bullets: ' + bullets.countLiving() + ' / ' + bullets.total, 32, 32);
|
||||
|
||||
game.debug.renderSpriteInfo(sprite, 32, 450);
|
||||
game.debug.renderSpriteCorners(sprite);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user