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
+73
View File
@@ -0,0 +1,73 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.stage.backgroundColor = '#007236';
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
game.load.image('phaser', 'assets/sprites/sonic_havok_sanity.png');
}
var cursors;
function create() {
// Modify the world and camera bounds
game.world.setBounds(-1000, -1000, 2000, 2000);
for (var i = 0; i < 100; i++)
{
game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
}
// This will create a new object called "cursors", inside it will contain 4 objects: up, down, left and right.
// These are all Phaser.Key objects, so anything you can do with a Key object you can do with these.
cursors = game.input.keyboard.createCursorKeys();
}
function update() {
// For example this checks if the up or down keys are pressed and moves the camera accordingly.
if (cursors.up.isDown)
{
// If the shift key is also pressed then the world is rotated
if (cursors.up.shiftKey)
{
game.world.rotation += 0.05;
}
else
{
game.camera.y -= 4;
}
}
else if (cursors.down.isDown)
{
if (cursors.down.shiftKey)
{
game.world.rotation -= 0.05;
}
else
{
game.camera.y += 4;
}
}
if (cursors.left.isDown)
{
game.camera.x -= 4;
}
else if (cursors.right.isDown)
{
game.camera.x += 4;
}
}
function render() {
game.debug.renderCameraInfo(game.camera, 32, 32);
}
-90
View File
@@ -1,90 +0,0 @@
<?php
$title = "Cursor Key Movement";
require('../head.php');
?>
<script type="text/javascript">
window.onload = function () {
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render : render });
function preload() {
game.stage.backgroundColor = '#007236';
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
game.load.image('phaser', 'assets/sprites/sonic_havok_sanity.png');
}
var cursors;
function create() {
// Modify the world and camera bounds
game.world.setBounds(-1000, -1000, 2000, 2000);
for (var i = 0; i < 100; i++)
{
game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
}
// This will create a new object called "cursors", inside it will contain 4 objects: up, down, left and right.
// These are all Phaser.Key objects, so anything you can do with a Key object you can do with these.
cursors = game.input.keyboard.createCursorKeys();
}
function update() {
// For example this checks if the up or down keys are pressed and moves the camera accordingly.
if (cursors.up.isDown)
{
// If the shift key is also pressed then the world is rotated
if (cursors.up.shiftKey)
{
game.world.rotation += 0.05;
}
else
{
game.camera.y -= 4;
}
}
else if (cursors.down.isDown)
{
if (cursors.down.shiftKey)
{
game.world.rotation -= 0.05;
}
else
{
game.camera.y += 4;
}
}
if (cursors.left.isDown)
{
game.camera.x -= 4;
}
else if (cursors.right.isDown)
{
game.camera.x += 4;
}
}
function render() {
game.debug.renderCameraInfo(game.camera, 32, 32);
}
};
</script>
<?php
require('../foot.php');
?>
+36
View File
@@ -0,0 +1,36 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render });
function preload() {
game.load.image('atari1', 'assets/sprites/atari130xe.png');
game.load.image('atari2', 'assets/sprites/atari800xl.png');
game.load.image('atari4', 'assets/sprites/atari800.png');
game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png');
game.load.image('duck', 'assets/sprites/darkwing_crazy.png');
game.load.image('firstaid', 'assets/sprites/firstaid.png');
game.load.image('diamond', 'assets/sprites/diamond.png');
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
}
function create() {
// This returns an array of all the image keys in the cache
var images = game.cache.getImageKeys();
var test = game.add.group();
// Now let's create some random sprites and enable them all for drag and 'bring to top'
for (var i = 0; i < 20; i++)
{
var tempSprite = test.create(game.world.randomX, game.world.randomY, game.rnd.pick(images));
tempSprite.inputEnabled = true;
tempSprite.input.enableDrag(false, true);
}
}
function render() {
game.debug.renderInputInfo(32, 32);
}
-51
View File
@@ -1,51 +0,0 @@
<?php
$title = "Test Title";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, render: render });
function preload() {
game.load.image('atari1', 'assets/sprites/atari130xe.png');
game.load.image('atari2', 'assets/sprites/atari800xl.png');
game.load.image('atari4', 'assets/sprites/atari800.png');
game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png');
game.load.image('duck', 'assets/sprites/darkwing_crazy.png');
game.load.image('firstaid', 'assets/sprites/firstaid.png');
game.load.image('diamond', 'assets/sprites/diamond.png');
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
}
function create() {
// This returns an array of all the image keys in the cache
var images = game.cache.getImageKeys();
var test = game.add.group();
// Now let's create some random sprites and enable them all for drag and 'bring to top'
for (var i = 0; i < 20; i++)
{
var tempSprite = test.create(game.world.randomX, game.world.randomY, game.rnd.pick(images));
tempSprite.inputEnabled = true;
tempSprite.input.enableDrag(false, true);
}
}
function render() {
game.debug.renderInputInfo(32, 32);
}
</script>
<?php
require('../foot.php');
?>
+24
View File
@@ -0,0 +1,24 @@
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
function preload() {
game.load.image('grid', 'assets/tests/debug-grid-1920x1920.png');
game.load.image('atari', 'assets/sprites/atari800xl.png');
}
function create() {
game.add.sprite(0, 0, 'grid');
atari1 = game.add.sprite(300, 300, 'atari');
// Input Enable the sprites
atari1.inputEnabled = true;
// Allow dragging
// enableDrag parameters = (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite)
atari1.input.enableDrag(true);
}
-39
View File
@@ -1,39 +0,0 @@
<?php
$title = "How to drag a sprite";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create });
function preload() {
game.load.image('grid', 'assets/tests/debug-grid-1920x1920.png');
game.load.image('atari', 'assets/sprites/atari800xl.png');
}
function create() {
game.add.sprite(0, 0, 'grid');
atari1 = game.add.sprite(300, 300, 'atari');
// Input Enable the sprites
atari1.inputEnabled = true;
// Allow dragging
// enableDrag parameters = (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite)
atari1.input.enableDrag(true);
}
</script>
<?php
require('../foot.php');
?>
+55
View File
@@ -0,0 +1,55 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create,render:render});
function preload() {
game.load.spritesheet('item', 'assets/buttons/number-buttons-90x90.png', 90, 90);
}
function create() {
// Add some items to left side, and set a onDragStop listener
// to limit its location when dropped.
var item;
for (var i = 0; i < 6; i++)
{
// Directly create sprites on the left group.
item = game.add.sprite(90, 90 * i, 'item', i);
// Enable input detection, then it's possible be dragged.
item.input.start(0,true);
// Make this item draggable.
item.input.enableDrag();
// Then we make it snap to left and right side,
// also we make it only snap when released.
item.input.enableSnap(90, 90, false, true);
// Limit drop location to only the 2 columns.
item.events.onDragStop.add(fixLocation);
}
}
function render() {
game.debug.renderText('Group Left.', 100, 560);
game.debug.renderText('Group Right.', 280, 560);
}
function fixLocation(item) {
// Move the items when it is already dropped.
if (item.x < 90) {
item.x = 90;
}
else if (item.x > 180 && item.x < 270) {
item.x = 180;
}
else if (item.x > 360) {
item.x = 270;
}
}
-63
View File
@@ -1,63 +0,0 @@
<?php
$title = "Using a drop event to control the drag and drop";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create,render:render});
function preload() {
game.load.spritesheet('item', 'assets/buttons/number-buttons-90x90.png', 90, 90);
}
function create() {
// Add some items to left side, and set a onDragStop listener
// to limit its location when dropped.
var item;
for (var i = 0; i < 6; i++) {
// Directly create sprites on the left group.
item = game.add.sprite(90, 90 * i, 'item', i);
// Enable input detection, then it's possible be dragged.
item.input.start(0,true);
// Make this item draggable.
item.input.enableDrag();
// Then we make it snap to left and right side,
// also we make it only snap when released.
item.input.enableSnap(90, 90, false, true);
// Limit drop location to only the 2 columns.
item.events.onDragStop.add(fixLocation);
}
}
function render() {
game.debug.renderText('Group Left.', 100, 560);
game.debug.renderText('Group Right.', 280, 560);
}
function fixLocation(item) {
// Move the items when it is already dropped.
if (item.x < 90) {
item.x = 90;
}
else if (item.x > 180 && item.x < 270) {
item.x = 180;
}
else if (item.x > 360) {
item.x = 270;
}
}
</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 sprite;
function create() {
sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'ball');
}
function update() {
// only move when you click
if (game.input.mousePointer.isDown)
{
// 400 is the speed it will move towards the mouse
game.physics.moveToPointer(sprite, 400);
// if it's overlapping the mouse, don't move any more
if (Phaser.Rectangle.contains(sprite.body, game.input.x, game.input.y))
{
sprite.body.velocity.setTo(0, 0);
}
}
else
{
sprite.body.velocity.setTo(0, 0);
}
}
-53
View File
@@ -1,53 +0,0 @@
<?php
$title = "Follow Mouse";
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 sprite;
function create() {
sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'ball');
}
function update() {
// only move when you click
if (game.input.mousePointer.isDown)
{
// 400 is the speed it will move towards the mouse
game.physics.moveToPointer(sprite, 400);
// if it's overlapping the mouse, don't move any more
if (Phaser.Rectangle.contains(sprite.body, game.input.x, game.input.y))
{
sprite.body.velocity.setTo(0, 0);
}
}
else
{
sprite.body.velocity.setTo(0, 0);
}
}
</script>
<?php
require('../foot.php');
?>
+58
View File
@@ -0,0 +1,58 @@
var game = new Phaser.Game(320, 240, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
// This sets a limit on the up-scale
game.stage.scale.maxWidth = 800;
game.stage.scale.maxHeight = 600;
// Then we tell Phaser that we want it to scale up to whatever the browser can handle, but to do it proportionally
game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
game.load.image('melon', 'assets/sprites/melon.png');
}
function create() {
//We increase the size of our game world
game.world.setBounds(0,0,2000, 2000);
for (var i = 0; i < 1000; i++)
{
//And spread some sprites inside it
game.add.sprite(game.world.randomX, game.world.randomY, 'melon');
}
}
function update() {
//This allows us to move the game camera using the keyboard
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
game.camera.x -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
game.camera.x += 4;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
game.camera.y -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
game.camera.y += 4;
}
}
function render() {
game.debug.renderInputInfo(16, 16);
}
-76
View File
@@ -1,76 +0,0 @@
<?php
$title = "Scale the game and explore it using the keyboard";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(320, 240, Phaser.CANVAS, '', { preload: preload, create: create,update:update,render:render});
function preload() {
// This sets a limit on the up-scale
game.stage.scale.maxWidth = 800;
game.stage.scale.maxHeight = 600;
// Then we tell Phaser that we want it to scale up to whatever the browser can handle, but to do it proportionally
game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
game.load.image('melon', 'assets/sprites/melon.png');
}
function create() {
//We increase the size of our game world
game.world.setBounds(0,0,2000, 2000);
for (var i = 0; i < 1000; i++)
{
//And spread some sprites inside it
game.add.sprite(game.world.randomX, game.world.randomY, 'melon');
}
}
function update() {
//This allows us to move the game camera using the keyboard
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
game.camera.x -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
game.camera.x += 4;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
game.camera.y -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
game.camera.y += 4;
}
}
function render() {
game.debug.renderInputInfo(16, 16);
}
</script>
<?php
require('../foot.php');
?>
+52
View File
@@ -0,0 +1,52 @@
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
function preload() {
game.load.image('phaser', 'assets/sprites/phaser-dude.png');
}
var sprite;
var upKey;
var downKey;
var leftKey;
var rightKey;
function create() {
game.stage.backgroundColor = '#736357';
sprite = game.add.sprite(300, 300, 'phaser');
// In this example we'll create 4 specific keys (up, down, left, right) and monitor them in our update function
upKey = game.input.keyboard.addKey(Phaser.Keyboard.UP);
downKey = game.input.keyboard.addKey(Phaser.Keyboard.DOWN);
leftKey = game.input.keyboard.addKey(Phaser.Keyboard.LEFT);
rightKey = game.input.keyboard.addKey(Phaser.Keyboard.RIGHT);
}
function update() {
if (upKey.isDown)
{
sprite.y--;
}
else if (downKey.isDown)
{
sprite.y++;
}
if (leftKey.isDown)
{
sprite.x--;
}
else if (rightKey.isDown)
{
sprite.x++;
}
}
-67
View File
@@ -1,67 +0,0 @@
<?php
$title = "Creating and using a Key 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('phaser', 'assets/sprites/phaser-dude.png');
}
var sprite;
var upKey;
var downKey;
var leftKey;
var rightKey;
function create() {
game.stage.backgroundColor = '#736357';
sprite = game.add.sprite(300, 300, 'phaser');
// In this example we'll create 4 specific keys (up, down, left, right) and monitor them in our update function
upKey = game.input.keyboard.addKey(Phaser.Keyboard.UP);
downKey = game.input.keyboard.addKey(Phaser.Keyboard.DOWN);
leftKey = game.input.keyboard.addKey(Phaser.Keyboard.LEFT);
rightKey = game.input.keyboard.addKey(Phaser.Keyboard.RIGHT);
}
function update() {
if (upKey.isDown)
{
sprite.y--;
}
else if (downKey.isDown)
{
sprite.y++;
}
if (leftKey.isDown)
{
sprite.x--;
}
else if (rightKey.isDown)
{
sprite.x++;
}
}
</script>
<?php
require('../foot.php');
?>
+43
View File
@@ -0,0 +1,43 @@
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
function preload() {
game.load.image('phaser', 'assets/sprites/phaser-dude.png');
game.load.image('logo', 'assets/sprites/phaser_tiny.png');
game.load.image('pineapple', 'assets/sprites/pineapple.png');
}
var key1;
var key2;
var key3;
function create() {
game.stage.backgroundColor = '#736357';
// Here we create 3 hotkeys, keys 1-3 and bind them all to their own functions
key1 = game.input.keyboard.addKey(Phaser.Keyboard.ONE);
key1.onDown.add(addPhaserDude, this);
key2 = game.input.keyboard.addKey(Phaser.Keyboard.TWO);
key2.onDown.add(addPhaserLogo, this);
key3 = game.input.keyboard.addKey(Phaser.Keyboard.THREE);
key3.onDown.add(addPineapple, this);
}
function addPhaserDude () {
game.add.sprite(game.world.randomX, game.world.randomY, 'phaser');
}
function addPhaserLogo () {
game.add.sprite(game.world.randomX, game.world.randomY, 'logo');
}
function addPineapple () {
game.add.sprite(game.world.randomX, game.world.randomY, 'pineapple');
}
-58
View File
@@ -1,58 +0,0 @@
<?php
$title = "Keyboard Hotkeys";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create });
function preload() {
game.load.image('phaser', 'assets/sprites/phaser-dude.png');
game.load.image('logo', 'assets/sprites/phaser_tiny.png');
game.load.image('pineapple', 'assets/sprites/pineapple.png');
}
var key1;
var key2;
var key3;
function create() {
game.stage.backgroundColor = '#736357';
// Here we create 3 hotkeys, keys 1-3 and bind them all to their own functions
key1 = game.input.keyboard.addKey(Phaser.Keyboard.ONE);
key1.onDown.add(addPhaserDude, this);
key2 = game.input.keyboard.addKey(Phaser.Keyboard.TWO);
key2.onDown.add(addPhaserLogo, this);
key3 = game.input.keyboard.addKey(Phaser.Keyboard.THREE);
key3.onDown.add(addPineapple, this);
}
function addPhaserDude () {
game.add.sprite(game.world.randomX, game.world.randomY, 'phaser');
}
function addPhaserLogo () {
game.add.sprite(game.world.randomX, game.world.randomY, 'logo');
}
function addPineapple () {
game.add.sprite(game.world.randomX, game.world.randomY, 'pineapple');
}
</script>
<?php
require('../foot.php');
?>
+32
View File
@@ -0,0 +1,32 @@
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
var phaser;
function preload() {
game.load.image('phaser', 'assets/sprites/phaser-dude.png');
}
function create() {
game.stage.backgroundColor = '#736357';
phaser = game.add.sprite(300, 300, 'phaser');
}
function update() {
if (game.input.keyboard.justPressed(Phaser.Keyboard.UP))
{
phaser.y--;
}
if (game.input.keyboard.justPressed(Phaser.Keyboard.DOWN))
{
phaser.y++;
}
}
-47
View File
@@ -1,47 +0,0 @@
<?php
$title = "Keyboard justPressed";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
var phaser;
function preload() {
game.load.image('phaser', 'assets/sprites/phaser-dude.png');
}
function create() {
game.stage.backgroundColor = '#736357';
phaser = game.add.sprite(300, 300, 'phaser');
}
function update() {
if (game.input.keyboard.justPressed(Phaser.Keyboard.UP))
{
phaser.y--;
}
if (game.input.keyboard.justPressed(Phaser.Keyboard.DOWN))
{
phaser.y++;
}
}
</script>
<?php
require('../foot.php');
?>
+80
View File
@@ -0,0 +1,80 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
var ufo;
var leftBtn;
var rightBtn;
var speed = 4;
function preload() {
game.world.setBounds(0,0,1280, 600);
game.load.image('ground', 'assets/tests/ground-2x.png');
game.load.image('river', 'assets/tests/river-2x.png');
game.load.image('sky', 'assets/tests/sky-2x.png');
game.load.image('cloud0', 'assets/tests/cloud-big-2x.png');
game.load.image('cloud1', 'assets/tests/cloud-narrow-2x.png');
game.load.image('cloud2', 'assets/tests/cloud-small-2x.png');
game.load.spritesheet('button', 'assets/buttons/arrow-button.png', 112, 95);
game.load.image('ufo', 'assets/sprites/ufo.png');
}
function create() {
// background images
game.add.tileSprite(0, 0,1280,600, 'sky');
game.add.sprite(0, 360, 'ground');
game.add.sprite(0, 400, 'river');
game.add.sprite(200, 120, 'cloud0');
game.add.sprite(-60, 120, 'cloud1');
game.add.sprite(900, 170, 'cloud2');
// Create a ufo sprite as player.
ufo = game.add.sprite(320, 240, 'ufo');
ufo.anchor.setTo(0.5, 0.5);
// Make the default camera follow the ufo.
game.camera.follow(ufo);
// Add 2 sprite to display hold direction.
leftBtn = game.add.sprite(160 - 112, 200, 'button', 0);
leftBtn.alpha = 0;
rightBtn = game.add.sprite(640 - 112, 200, 'button', 1);
rightBtn.alpha = 0;
}
function update() {
// Check key states every frame.
// Move ONLY one of the left and right key is hold.
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
ufo.x -= speed;
ufo.angle = -15;
leftBtn.alpha = 0.6;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)
{
ufo.x += speed;
ufo.angle = 15;
rightBtn.alpha = 0.6;
}
else
{
ufo.rotation = 0;
leftBtn.alpha = rightBtn.alpha = 0;
}
}
function render() {
game.debug.renderText('Hold left/right to move the ufo.');
}
-87
View File
@@ -1,87 +0,0 @@
<?php
$title = "Using the keyboard to move a sprite";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create,update:update,render:render });
var ufo,
leftBtn,
rightBtn;
var speed=4;
function preload() {
game.world.setBounds(0,0,1280, 600);
game.load.image('ground', 'assets/tests/ground-2x.png');
game.load.image('river', 'assets/tests/river-2x.png');
game.load.image('sky', 'assets/tests/sky-2x.png');
game.load.image('cloud0', 'assets/tests/cloud-big-2x.png');
game.load.image('cloud1', 'assets/tests/cloud-narrow-2x.png');
game.load.image('cloud2', 'assets/tests/cloud-small-2x.png');
game.load.spritesheet('button', 'assets/buttons/arrow-button.png', 112, 95);
game.load.image('ufo', 'assets/sprites/ufo.png');
}
function create() {
// background images
game.add.tileSprite(0, 0,1280,600, 'sky');
game.add.sprite(0, 360, 'ground');
game.add.sprite(0, 400, 'river');
game.add.sprite(200, 120, 'cloud0');
game.add.sprite(-60, 120, 'cloud1');
game.add.sprite(900, 170, 'cloud2');
// Create a ufo sprite as player.
ufo = game.add.sprite(320, 240, 'ufo');
ufo.anchor.setTo(0.5, 0.5);
// Make the default camera follow the ufo.
game.camera.follow(ufo);
// Add 2 sprite to display hold direction.
leftBtn = game.add.sprite(160 - 112, 200, 'button', 0);
leftBtn.alpha = 0;
rightBtn = game.add.sprite(640 - 112, 200, 'button', 1);
rightBtn.alpha = 0;
}
function update() {
// Check key states every frame.
// Move ONLY one of the left and right key is hold.
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT) &&
!game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
ufo.x -= speed;
ufo.angle = -15;
leftBtn.alpha = 0.6;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT) &&
!game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
ufo.x += speed;
ufo.angle = 15;
rightBtn.alpha = 0.6;
}
else {
ufo.rotation = 0;
leftBtn.alpha = rightBtn.alpha = 0;
}
}
function render() {
game.debug.renderText('Hold left/right to move the ufo.');
}
</script>
<?php
require('../foot.php');
?>
@@ -0,0 +1,37 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render });
function preload() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.load.image('sprite', 'assets/sprites/parsec.png');
}
var sprite;
function create() {
game.stage.backgroundColor = 'rgb(85,85,85)';
sprite = game.add.sprite(200, 400, 'sprite');
// Enable Input detection. Sprites have this disabled by default,
// so you have to start it if you want to interact with them.
sprite.input.start(0,true);
// This allows you to drag the sprite. The parameter controls if you drag from the position you touched it (false)
// or if it will snap to the center (true)
sprite.input.enableDrag();
// This will lock the sprite so it can only be dragged horizontally, not vertically
sprite.input.allowVerticalDrag = false;
}
function render() {
game.debug.renderInputInfo(32, 32);
game.debug.renderSpriteInputInfo(sprite, 300, 32);
}
@@ -1,54 +0,0 @@
<?php
$title = "Enable horizontal drag bounds";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create,render:render});
function preload() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.load.image('sprite', 'assets/sprites/parsec.png');
}
var sprite;
function create() {
game.stage.backgroundColor = 'rgb(85,85,85)';
sprite = game.add.sprite(200, 400, 'sprite');
// Enable Input detection. Sprites have this disabled by default,
// so you have to start it if you want to interact with them.
sprite.input.start(0,true);
// This allows you to drag the sprite. The parameter controls if you drag from the position you touched it (false)
// or if it will snap to the center (true)
sprite.input.enableDrag();
// This will lock the sprite so it can only be dragged horizontally, not vertically
sprite.input.allowVerticalDrag = false;
}
function render() {
game.debug.renderInputInfo(32, 32);
game.debug.renderSpriteInputInfo(sprite, 300, 32);
}
</script>
<?php
require('../foot.php');
?>
+37
View File
@@ -0,0 +1,37 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render });
function preload() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.load.image('sprite', 'assets/sprites/darkwing_crazy.png');
}
var sprite;
function create() {
game.stage.backgroundColor = 'rgb(85,85,85)';
sprite = game.add.sprite(200, 200, 'sprite');
// Enable Input detection. Sprites have this disabled by default,
// so you have to start it if you want to interact with them.
sprite.input.start(0,true);
// This allows you to drag the sprite. The parameter controls if you drag from the position you touched it (false)
// or if it will snap to the center (true)
sprite.input.enableDrag();
// This will lock the sprite so it can only be dragged vertically, not horizontally
sprite.input.allowHorizontalDrag = false;
}
function render() {
game.debug.renderInputInfo(32, 32);
game.debug.renderSpriteInputInfo(sprite, 300, 32);
}
-54
View File
@@ -1,54 +0,0 @@
<?php
$title = "Enable vertical drag bounds";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create,render:render});
function preload() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.load.image('sprite', 'assets/sprites/darkwing_crazy.png');
}
var sprite;
function create() {
game.stage.backgroundColor = 'rgb(85,85,85)';
sprite = game.add.sprite(200, 200, 'sprite');
// Enable Input detection. Sprites have this disabled by default,
// so you have to start it if you want to interact with them.
sprite.input.start(0,true);
// This allows you to drag the sprite. The parameter controls if you drag from the position you touched it (false)
// or if it will snap to the center (true)
sprite.input.enableDrag();
// This will lock the sprite so it can only be dragged vertically, not horizontally
sprite.input.allowHorizontalDrag = false;
}
function render() {
game.debug.renderInputInfo(32, 32);
game.debug.renderSpriteInputInfo(sprite, 300, 32);
}
</script>
<?php
require('../foot.php');
?>
+32
View File
@@ -0,0 +1,32 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { 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);
}
-44
View File
@@ -1,44 +0,0 @@
<?php
$title = "Multi Touch";
require('../head.php');
?>
<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
require('../foot.php');
?>
+109
View File
@@ -0,0 +1,109 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
var ufo;
var leftBtn;
var rightBtn;
var speed = 4;
function preload() {
game.world.setBounds(0, 0, 1280, 600);
game.load.image('ground', 'assets/tests/ground-2x.png');
game.load.image('river', 'assets/tests/river-2x.png');
game.load.image('sky', 'assets/tests/sky-2x.png');
game.load.image('cloud0', 'assets/tests/cloud-big-2x.png');
game.load.image('cloud1', 'assets/tests/cloud-narrow-2x.png');
game.load.image('cloud2', 'assets/tests/cloud-small-2x.png');
game.load.spritesheet('button', 'assets/buttons/arrow-button.png', 112, 95);
game.load.image('spacebar', 'assets/buttons/spacebar.png');
game.load.image('ufo', 'assets/sprites/ufo.png');
}
function create() {
// background images
game.add.sprite(0, 0, 'sky');
game.add.sprite(0, 360, 'ground');
game.add.sprite(0, 400, 'river');
game.add.sprite(200, 120, 'cloud0');
game.add.sprite(-60, 120, 'cloud1');
game.add.sprite(900, 170, 'cloud2');
// Create a ufo sprite as a player.
ufo = game.add.sprite(320, 240, 'ufo');
ufo.anchor.setTo(0.5, 0.5);
// Make the camera follow the ufo.
game.camera.follow(ufo);
// Add 2 sprite to display hold direction.
leftBtn = game.add.sprite(160 - 112, 200, 'button', 0);
leftBtn.alpha = 0;
rightBtn = game.add.sprite(640 - 112, 200, 'button', 1);
rightBtn.alpha = 0;
// Add a sprite to display spacebar press.
spaceBtn = game.add.sprite(400 - 112, 100, 'spacebar');
spaceBtn.alpha = 0;
// Prevent directions and space key events bubbling up to browser,
// since these keys will make web page scroll which is not
// expected.
game.input.keyboard.addKeyCapture([
Phaser.Keyboard.LEFT,
Phaser.Keyboard.RIGHT,
Phaser.Keyboard.UP,
Phaser.Keyboard.DOWN,
Phaser.Keyboard.SPACEBAR
]);
}
function update() {
// Check key states every frame.
// Move ONLY one of the left and right key is hold.
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
ufo.x -= speed;
ufo.angle = -15;
leftBtn.alpha = 0.6;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
ufo.x += speed;
ufo.angle = 15;
rightBtn.alpha = 0.6;
}
else
{
ufo.rotation = 0;
leftBtn.alpha = rightBtn.alpha = 0;
}
// 50 as a second parameter is a good choice if you are running 60FPS.
if (game.input.keyboard.justPressed(Phaser.Keyboard.SPACEBAR, 50))
{
console.log('space bar pressed');
spaceBtn.alpha = 1;
}
if (spaceBtn.alpha > 0)
{
spaceBtn.alpha -= 0.03;
}
}
function render() {
game.debug.renderText('Hold left/right to move the ufo.', 16, 32);
game.debug.renderText('Direction and Space key events are stopped by Phaser now,', 16, 48);
game.debug.renderText('so they will no longer be sent to the browser', 16, 64);
game.debug.renderText('Now you can press UP/DOWN or SPACE to see what happened.', 16, 80);
}
@@ -1,118 +0,0 @@
<?php
$title = "Overriding the browser's default keyboard behaviour";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create,update:update,render:render });
var ufo,
leftBtn,
rightBtn;
var speed=4;
function preload() {
game.world.setBounds(0,0,1280, 600);
game.load.image('ground', 'assets/tests/ground-2x.png');
game.load.image('river', 'assets/tests/river-2x.png');
game.load.image('sky', 'assets/tests/sky-2x.png');
game.load.image('cloud0', 'assets/tests/cloud-big-2x.png');
game.load.image('cloud1', 'assets/tests/cloud-narrow-2x.png');
game.load.image('cloud2', 'assets/tests/cloud-small-2x.png');
game.load.spritesheet('button', 'assets/buttons/arrow-button.png', 112, 95);
game.load.image('spacebar', 'assets/buttons/spacebar.png');
game.load.image('ufo', 'assets/sprites/ufo.png');
}
function create() {
// background images
game.add.sprite(0, 0, 'sky');
game.add.sprite(0, 360, 'ground');
game.add.sprite(0, 400, 'river');
game.add.sprite(200, 120, 'cloud0');
game.add.sprite(-60, 120, 'cloud1');
game.add.sprite(900, 170, 'cloud2');
// Create a ufo sprite as a player.
ufo = game.add.sprite(320, 240, 'ufo');
ufo.anchor.setTo(0.5, 0.5);
// Make the camera follow the ufo.
game.camera.follow(ufo);
// Add 2 sprite to display hold direction.
leftBtn = game.add.sprite(160 - 112, 200, 'button', 0);
leftBtn.alpha = 0;
rightBtn = game.add.sprite(640 - 112, 200, 'button', 1);
rightBtn.alpha = 0;
// Add a sprite to display spacebar press.
spaceBtn = game.add.sprite(400 - 112, 100, 'spacebar');
spaceBtn.alpha = 0;
// Prevent directions and space key events bubbling up to browser,
// since these keys will make web page scroll which is not
// expected.
game.input.keyboard.addKeyCapture([
Phaser.Keyboard.LEFT,
Phaser.Keyboard.RIGHT,
Phaser.Keyboard.UP,
Phaser.Keyboard.DOWN,
Phaser.Keyboard.SPACEBAR
]);
}
function update() {
// Check key states every frame.
// Move ONLY one of the left and right key is hold.
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT) &&
!game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
ufo.x -= speed;
ufo.angle = -15;
leftBtn.alpha = 0.6;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT) &&
!game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
ufo.x += speed;
ufo.angle = 15;
rightBtn.alpha = 0.6;
}
else {
ufo.rotation = 0;
leftBtn.alpha = rightBtn.alpha = 0;
}
// 50 as a second parameter is a good choice if you are running 60FPS.
if (game.input.keyboard.justPressed(Phaser.Keyboard.SPACEBAR, 50)) {
console.log('space bar pressed');
spaceBtn.alpha = 1;
}
if (spaceBtn.alpha > 0) {
spaceBtn.alpha -= 0.03;
}
}
function render() {
game.debug.renderText('Hold left/right to move the ufo.', 16, 32);
game.debug.renderText('Direction and Space key events are stopped by Phaser now,', 16, 48);
game.debug.renderText('so they will no longer be sent to the browser', 16, 64);
game.debug.renderText('Now you can press UP/DOWN or SPACE to see what happened.', 16, 80);
}
</script>
<?php
require('../foot.php');
?>
@@ -0,0 +1,47 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('bunny', 'assets/sprites/bunny.png');
}
var b;
function create() {
b = game.add.sprite(game.world.centerX, game.world.centerY, 'bunny');
b.anchor.setTo(0.5, 0.5);
// Listen for input events on this sprite
b.inputEnabled = true;
// Check the pixel data of the sprite
b.input.pixelPerfect = true;
// Enable the hand cursor
b.input.useHandCursor = true;
b.events.onInputOver.add(overSprite, this);
b.events.onInputOut.add(outSprite, this);
}
function overSprite() {
console.log('over');
}
function outSprite() {
console.log('out');
}
function update() {
b.angle += 0.1;
}
function render() {
game.debug.renderSpriteInputInfo(b, 32, 32);
}
@@ -0,0 +1,98 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
game.load.image('stars', 'assets/misc/starfield.jpg');
}
var b;
var camSpeed = 8;
var s;
function create() {
// Make our world big ...
game.world.setBounds(0,0,4000, 2000);
// Scrolling background
s = game.add.tileSprite(0, 0, 4000, 600, 'stars');
b = game.add.sprite(200, 200, 'mummy');
b.anchor.setTo(0.5, 0.5);
b.scale.setTo(6, 6);
b.animations.add('walk');
b.animations.play('walk', 5, true);
b.body.velocity.setTo(50, 0);
// Listen for input events on this sprite
b.inputEnabled = true;
// Check the pixel data of the sprite
b.input.pixelPerfect = true;
// Enable the hand cursor
b.input.useHandCursor = true;
b.events.onInputOver.add(overSprite, this);
b.events.onInputOut.add(outSprite, this);
}
function overSprite() {
console.log('over');
}
function outSprite() {
console.log('out');
}
function update() {
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
game.camera.x -= camSpeed;
if (!game.camera.atLimit.x)
{
s.tilePosition.x += camSpeed;
}
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
game.camera.x += camSpeed;
if (!game.camera.atLimit.x)
{
s.tilePosition.x -= camSpeed;
}
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
game.camera.y -= camSpeed;
if (!game.camera.atLimit.y)
{
s.tilePosition.y += camSpeed;
}
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
game.camera.y += camSpeed;
if (!game.camera.atLimit.y)
{
s.tilePosition.y -= camSpeed;
}
}
}
function render() {
game.debug.renderSpriteInputInfo(b, 32, 32);
}
@@ -1,113 +0,0 @@
<?php
$title = "Using pixel perfect plus scrolling background";
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.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
game.load.image('stars', 'assets/misc/starfield.jpg');
}
var b;
var camSpeed = 8;
var s;
function create() {
// Make our world big ...
game.world.setBounds(0,0,4000, 2000);
// Scrolling background
s = game.add.tileSprite(0, 0, 4000, 600, 'stars');
b = game.add.sprite(200, 200, 'mummy');
b.anchor.setTo(0.5, 0.5);
b.scale.setTo(6, 6);
b.animations.add('walk');
b.animations.play('walk', 5, true);
b.body.velocity.setTo(50, 0);
// Listen for input events on this sprite
b.inputEnabled = true;
// Check the pixel data of the sprite
b.input.pixelPerfect = true;
// Enable the hand cursor
b.input.useHandCursor = true;
b.events.onInputOver.add(overSprite, this);
b.events.onInputOut.add(outSprite, this);
}
function overSprite() {
console.log('over');
}
function outSprite() {
console.log('out');
}
function update() {
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
game.camera.x -= camSpeed;
if (!game.camera.atLimit.x)
{
s.tilePosition.x += camSpeed;
}
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
game.camera.x += camSpeed;
if (!game.camera.atLimit.x)
{
s.tilePosition.x -= camSpeed;
}
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
game.camera.y -= camSpeed;
if (!game.camera.atLimit.y)
{
s.tilePosition.y += camSpeed;
}
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
game.camera.y += camSpeed;
if (!game.camera.atLimit.y)
{
s.tilePosition.y -= camSpeed;
}
}
}
function render() {
game.debug.renderSpriteInputInfo(b, 32, 32);
}
</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, render: render });
function preload() {
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
}
var b;
function create() {
b = game.add.sprite(game.world.centerX, game.world.centerY, 'mummy');
b.anchor.setTo(0.5, 0.5);
b.scale.setTo(6, 6);
b.animations.add('walk');
b.animations.play('walk', 5, true);
// Listen for input events on this sprite
b.inputEnabled = true;
// Check the pixel data of the sprite
b.input.pixelPerfect = true;
// Enable the hand cursor
b.input.useHandCursor = true;
b.events.onInputOver.add(overSprite, this);
b.events.onInputOut.add(outSprite, this);
}
function overSprite() {
console.log('over');
}
function outSprite() {
console.log('out');
}
function render() {
game.debug.renderSpriteInputInfo(b, 32, 32);
}
@@ -1,61 +0,0 @@
<?php
$title = "Enabling pixel perfect hit detection on a spritesheet";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, render: render });
function preload() {
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
}
var b;
function create() {
b = game.add.sprite(game.world.centerX, game.world.centerY, 'mummy');
b.anchor.setTo(0.5, 0.5);
b.scale.setTo(6, 6);
b.animations.add('walk');
b.animations.play('walk', 5, true);
// Listen for input events on this sprite
b.inputEnabled = true;
// Check the pixel data of the sprite
b.input.pixelPerfect = true;
// Enable the hand cursor
b.input.useHandCursor = true;
b.events.onInputOver.add(overSprite, this);
b.events.onInputOut.add(outSprite, this);
}
function overSprite() {
console.log('over');
}
function outSprite() {
console.log('out');
}
function render() {
game.debug.renderSpriteInputInfo(b, 32, 32);
}
</script>
<?php
require('../foot.php');
?>
-62
View File
@@ -1,62 +0,0 @@
<?php
$title = "Enabling pixel perfect hit detection";
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('bunny', 'assets/sprites/bunny.png');
}
var b;
function create() {
b = game.add.sprite(game.world.centerX, game.world.centerY, 'bunny');
b.anchor.setTo(0.5, 0.5);
// Listen for input events on this sprite
b.inputEnabled = true;
// Check the pixel data of the sprite
b.input.pixelPerfect = true;
// Enable the hand cursor
b.input.useHandCursor = true;
b.events.onInputOver.add(overSprite, this);
b.events.onInputOut.add(outSprite, this);
}
function overSprite() {
console.log('over');
}
function outSprite() {
console.log('out');
}
function update() {
b.angle += 0.1;
}
function render() {
game.debug.renderSpriteInputInfo(b, 32, 32);
}
</script>
<?php
require('../foot.php');
?>
+35
View File
@@ -0,0 +1,35 @@
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
function preload() {
game.load.image('grid', 'assets/tests/debug-grid-1920x1920.png');
game.load.image('atari1', 'assets/sprites/atari130xe.png');
game.load.image('atari2', 'assets/sprites/atari800xl.png');
}
function create() {
game.add.sprite(0, 0, 'grid');
atari1 = game.add.sprite(128, 128, 'atari1');
atari2 = game.add.sprite(256, 256, 'atari2');
// Input Enable the sprites
atari1.inputEnabled = true;
atari2.inputEnabled = true;
// Allow dragging
// enableDrag parameters = (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite)
atari1.input.enableDrag();
atari2.input.enableDrag();
// Enable snapping. For the atari1 sprite it will snap as its dragged around and on release.
// The snap is set to every 32x32 pixels.
atari1.input.enableSnap(32, 32, true, true);
// For the atari2 sprite it will snap only when released, not on drag.
atari2.input.enableSnap(32, 32, false, true);
}
-50
View File
@@ -1,50 +0,0 @@
<?php
$title = "Snap on Drag Example";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create });
function preload() {
game.load.image('grid', 'assets/tests/debug-grid-1920x1920.png');
game.load.image('atari1', 'assets/sprites/atari130xe.png');
game.load.image('atari2', 'assets/sprites/atari800xl.png');
}
function create() {
game.add.sprite(0, 0, 'grid');
atari1 = game.add.sprite(128, 128, 'atari1');
atari2 = game.add.sprite(256, 256, 'atari2');
// Input Enable the sprites
atari1.inputEnabled = true;
atari2.inputEnabled = true;
// Allow dragging
// enableDrag parameters = (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite)
atari1.input.enableDrag();
atari2.input.enableDrag();
// Enable snapping. For the atari1 sprite it will snap as its dragged around and on release.
// The snap is set to every 32x32 pixels.
atari1.input.enableSnap(32, 32, true, true);
// For the atari2 sprite it will snap only when released, not on drag.
atari2.input.enableSnap(32, 32, false, true);
}
</script>
<?php
require('../foot.php');
?>