Merge pull request #104 from alvinsight/dev

Loads of new examples, some more bug fixes, all of them work beautifully
This commit is contained in:
Richard Davey 2013-10-14 11:37:18 -07:00
commit 6147e07a5f
24 changed files with 400 additions and 38 deletions

View file

@ -7,7 +7,7 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create });
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create });
function preload() {
game.load.atlas('bot', 'assets/misc/NumberSprite.png', 'assets/misc/NumberSprite.json');
@ -22,7 +22,7 @@
bot.animations.add('num3', ['num30000','num30001','num30002','num30003','num30004','num30005'], 24, false, false);
// bot.animations.play('num1', 15, true);
bot.animations.play('num2', 15, true);
//bot.animations.play('num2', 15, true);
// bot.animations.play('num3', 15, true);
}

View file

@ -46,7 +46,7 @@
// background images
game.add.sprite(0, 0, 'sky');
game.add.tileSprite(0, 0,1400,600, 'sky');
game.add.sprite(0, 360, 'ground');
game.add.sprite(0, 400, 'river');
game.add.sprite(200, 120, 'cloud0');

View file

@ -12,7 +12,7 @@
function preload() {
game.world.setBounds(1920, 1200);
game.world.setBounds(0,0,1920, 1200);
game.load.image('backdrop', 'assets/pics/remember-me.jpg');
game.load.image('card', 'assets/sprites/mana_card.png');

View file

@ -56,16 +56,16 @@
function update() {
sprite.velocity.x = 0;
sprite.velocity.y = 0;
sprite.body.velocity.x = 0;
sprite.body.velocity.y = 0;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
sprite.velocity.x = -200;
sprite.body.velocity.x = -200;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
sprite.velocity.x = 200;
sprite.body.velocity.x = 200;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))
@ -86,7 +86,7 @@
if (bullet)
{
bullet.reset(sprite.x + 6, sprite.y - 8);
bullet.velocity.y = -300;
bullet.body.velocity.y = -300;
bulletTime = game.time.now + 250;
}
}

View file

@ -49,25 +49,25 @@
function update() {
sprite.velocity.x = 0;
sprite.velocity.y = 0;
sprite.body.velocity.x = 0;
sprite.body.velocity.y = 0;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
sprite.velocity.x = -200;
sprite.body.velocity.x = -200;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
sprite.velocity.x = 200;
sprite.body.velocity.x = 200;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
sprite.velocity.y = -200;
sprite.body.velocity.y = -200;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
sprite.velocity.y = 200;
sprite.body.velocity.y = 200;
}
game.physics.collide(sprite, group, collisionHandler, null, this);

View file

@ -55,8 +55,6 @@
graphics.moveTo(30,30);
graphics.lineTo(600, 300);
game.add.tween(graphics).to({ x: 200 }, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true);
}

View file

@ -65,16 +65,16 @@
function update() {
player.velocity.x = 0;
player.velocity.y = 0;
player.body.velocity.x = 0;
player.body.velocity.y = 0;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
player.velocity.x = -200;
player.body.velocity.x = -200;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
player.velocity.x = 200;
player.body.velocity.x = 200;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))
@ -95,7 +95,7 @@
if (bullet)
{
bullet.reset(player.x, player.y - 8);
bullet.velocity.y = -300;
bullet.body.velocity.y = -300;
bulletTime = game.time.now + 250;
}
}

View file

@ -0,0 +1,32 @@
<?php
$title = "Circle";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', {create: create,render:render});
var circle;
var floor;
function create() {
circle = new Phaser.Circle(game.world.centerX, 100,64);
}
function render () {
game.debug.renderCircle(circle,'#cfffff');
game.debug.renderText('Diameter : '+circle.diameter,50,200);
game.debug.renderText('Circumference : '+circle.circumference(),50,230);
}
</script>
<?php
require('../foot.php');
?>

View file

@ -0,0 +1,32 @@
<?php
$title = "Rectangle";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', {create: create});
function create() {
var graphics = game.add.graphics(50,50);
// set a fill and line style
graphics.beginFill(0xFF0000);
graphics.lineStyle(10, 0xFF0000, 1);
// draw a shape
graphics.moveTo(50,50);
graphics.lineTo(250, 50);
graphics.endFill();
}
</script>
<?php
require('../foot.php');
?>

View file

@ -0,0 +1,70 @@
<?php
$title = "Rotate point";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', {create: create,update:update,render:render});
var p1;
var p2;
var p3;
var p4;
var d2 = 0;
var d3 = 0;
var d4 = 0;
function create() {
p1 = new Phaser.Point(game.world.centerX, game.world.centerY);
p2 = new Phaser.Point(p1.x - 50, p1.y - 50);
p3 = new Phaser.Point(p2.x - 50, p2.y - 50);
p4 = new Phaser.Point(p3.x - 50, p3.y - 50);
}
function update() {
p2.rotate(p1.x, p1.y, game.math.wrapAngle(d2), true, 150);
p3.rotate(p2.x, p2.y, game.math.wrapAngle(d3), true, 50);
p4.rotate(p3.x, p3.y, game.math.wrapAngle(d4), true, 100);
d2 += 1;
d3 += 4;
d4 += 6;
}
function render() {
game.context.strokeStyle = 'rgb(0,255,255)';
game.context.beginPath();
game.context.moveTo(p1.x, p1.y);
game.context.lineTo(p2.x, p2.y);
game.context.lineTo(p3.x, p3.y);
game.context.lineTo(p4.x, p4.y);
game.context.stroke();
game.context.closePath();
game.context.fillStyle = 'rgb(255,255,0)';
game.context.fillRect(p1.x, p1.y, 4, 4);
game.context.fillStyle = 'rgb(255,0,0)';
game.context.fillRect(p2.x, p2.y, 4, 4);
game.context.fillStyle = 'rgb(0,255,0)';
game.context.fillRect(p3.x, p3.y, 4, 4);
game.context.fillStyle = 'rgb(255,0,255)';
game.context.fillRect(p4.x, p4.y, 4, 4);
}
</script>
<?php
require('../foot.php');
?>

View file

@ -0,0 +1,30 @@
<?php
$title = "Rectangle";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', {create: create,render:render});
var floor;
function create() {
// A simple floor
floor = new Phaser.Rectangle(0, 550,800,50);
}
function render () {
game.debug.renderRectangle(floor,'#0fffff');
}
</script>
<?php
require('../foot.php');
?>

View file

@ -0,0 +1,47 @@
<?php
$title = "Rotate point";
require('../head.php');
?>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', {create: create,update:update,render:render});
var p1;
var p2;
var d=0;
function create() {
p1 = new Phaser.Point(200, 300);
p2 = new Phaser.Point(300, 300);
}
function update() {
p1.rotate(p2.x, p2.y, game.math.wrapAngle(d), true);
d++;
}
function render() {
game.context.fillStyle = 'rgb(255,255,0)';
game.context.fillRect(p1.x, p1.y, 4, 4);
game.context.fillStyle = 'rgb(255,0,0)';
game.context.fillRect(p2.x, p2.y, 4, 4);
}
</script>
<?php
require('../foot.php');
?>

View file

@ -11,7 +11,7 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create,render:render});
function preload() {
game.world.setBounds(1280, 800);
game.world.setBounds(0,0,1280, 800);
game.load.image('ground', 'assets/tests/ground-2x.png');
game.load.image('river', 'assets/tests/river-2x.png');

View file

@ -27,7 +27,7 @@
function create() {
//We increase the size of our game world
game.world.setBounds(2000, 2000);
game.world.setBounds(0,0,2000, 2000);
for (var i = 0; i < 1000; i++)
{

View file

@ -15,7 +15,7 @@
var speed=4;
function preload() {
game.world.setBounds(1280, 600);
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');
@ -31,7 +31,7 @@
}
function create() {
// background images
game.add.sprite(0, 0, 'sky');
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');

View file

@ -15,7 +15,7 @@
var speed=4;
function preload() {
game.world.setBounds(1280, 600);
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');

View file

@ -1,5 +1,5 @@
<?php
$title = "Test Title";
$title = "Using pixel perfect plus scrolling background";
require('../head.php');
?>
@ -23,10 +23,10 @@
function create() {
// Make our world big ...
game.world.setBounds(4000, 2000);
game.world.setBounds(0,0,4000, 2000);
// Scrolling background
s = game.add.tileSprite(0, 0, 800, 600, 'stars');
s = game.add.tileSprite(0, 0, 4000, 600, 'stars');
b = game.add.sprite(200, 200, 'mummy');
b.anchor.setTo(0.5, 0.5);

View file

@ -1,5 +1,5 @@
<?php
$title = "Test Title";
$title = "Enabling pixel perfect hit detection on a spritesheet";
require('../head.php');
?>
@ -7,7 +7,7 @@
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, render: render });
function preload() {
@ -47,10 +47,6 @@
console.log('out');
}
function update() {
// b.angle += 0.1;
}
function render() {
game.debug.renderSpriteInputInfo(b, 32, 32);

View file

@ -1,5 +1,5 @@
<?php
$title = "Test Title";
$title = "Enabling pixel perfect hit detection";
require('../head.php');
?>

View file

@ -0,0 +1,45 @@
<?php
$title = "Preload 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('backdrop', 'assets/pics/remember-me.jpg');
game.load.image('card', 'assets/sprites/mana_card.png');
game.load.image('rewarding', 'assets/pics/destop-rewarding.png');
game.load.image('unknown', 'assets/pics/destop-unknown.png');
game.load.image('wheel', 'assets/pics/large-color-wheel.png');
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');
game.load.setPreloadSprite('unknown',1);
}
function create() {
game.add.sprite(200, 200, 'rewarding');
}
</script>
<?php
require('../foot.php');
?>

View file

@ -20,7 +20,7 @@
function create() {
game.world.setBounds(2000, 2000);
game.world.setBounds(0,0,2000, 2000);
aliens = [];

View file

@ -0,0 +1,40 @@
<?php
$title = "Sprite is out of world bounds";
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('pineapple', 'assets/sprites/pineapple.png');
}
var pineapples;
function create() {
pineapples = game.add.group();
for (var i = 0; i < 10; i++){
var pineapple = pineapples.create(200 + i * 48,50, 'pineapple');
//This allows your sprite to collide with the world bounds like they were rigid objects
pineapple.body.collideWorldBounds=true;
pineapple.body.gravity.x = game.rnd.integerInRange(-5,5);
pineapple.body.gravity.y = 5 + Math.random() * 10;
pineapple.body.bounce.setTo(0.7,0.4);
}
}
</script>
<?php
require('../foot.php');
?>

View file

@ -0,0 +1,39 @@
<?php
$title = "Destoying 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('plane', 'assets/misc/boss1.png');
game.load.image('sky', 'assets/tests/sky-2x.png');
}
function create() {
game.add.sprite(0, 0, 'sky');
for(var i=0;i<15;i++){
var sprite=game.add.sprite(game.world.randomX, game.world.randomY, 'plane');
sprite.inputEnabled=true;
sprite.input.useHandCursor=true;
sprite.events.onInputDown.add(destoyIt,this);
}
}
function destoyIt (sprite) {
sprite.destroy();
}
</script>
<?php
require('../foot.php');
?>

View file

@ -0,0 +1,33 @@
<?php
$title = "Scaling 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('disk', 'assets/sprites/darkwing_crazy.png');
}
function create() {
for(var i=0;i<15;i++){
var sprite=game.add.sprite(game.world.randomX, game.world.randomY, 'disk');
var rand=game.rnd.realInRange(-2,6);
sprite.scale.setTo(rand,rand);
}
}
</script>
<?php
require('../foot.php');
?>