Fixed lots of examples and added the missing Line.js.

This commit is contained in:
photonstorm 2014-01-31 14:12:03 +00:00
parent 26f2b2a931
commit 5e182d317b
14 changed files with 147 additions and 100 deletions

View file

@ -12,7 +12,7 @@ By Richard Davey, [Photon Storm](http://www.photonstorm.com)
View the [Official Website](http://phaser.io)<br />
Follow on [Twitter](https://twitter.com/photonstorm)<br />
Join the [Forum](http://www.html5gamedevs.com/forum/14-phaser/)<br />
Try out 200+ [Phaser Examples](http://gametest.mobi/phaser/examples/)<br />
Try out 210+ [Phaser Examples](http://examples.phaser.io)<br />
Read the [documentation online](http://docs.phaser.io)
[Subscribe to our new Phaser Newsletter](https://confirmsubscription.com/h/r/369DE48E3E86AF1E). We'll email you when new versions are released as well as send you our regular Phaser game making magazine.
@ -188,6 +188,7 @@ Updates:
* Phaser.Math.min enhanced so you can now pass in either an array of numbers or lots of numbers as parameters to get the lowest.
* Phaser.Math.max added as the opposite of Math.min.
* Phaser.Math.minProperty and maxProperty added. Like Math.min/max but can be given a property an an array or list of objects to inspect.
* Added 'full' paramter to Body.reset, allowing you to control if motion or all data is reset or not.
Bug Fixes:

View file

@ -106,6 +106,7 @@
<script src="../src/math/Math.js"></script>
<script src="../src/math/QuadTree.js"></script>
<script src="../src/geom/Line.js"></script>
<script src="../src/geom/Circle.js"></script>
<script src="../src/geom/Point.js"></script>
<script src="../src/geom/Rectangle.js"></script>

View file

@ -106,6 +106,7 @@
<script src="../src/math/Math.js"></script>
<script src="../src/math/QuadTree.js"></script>
<script src="../src/geom/Line.js"></script>
<script src="../src/geom/Circle.js"></script>
<script src="../src/geom/Point.js"></script>
<script src="../src/geom/Rectangle.js"></script>

View file

@ -0,0 +1,65 @@
{ "height":19,
"layers":[
{
"data":[1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 11, 1, 1, 9, 13, 1, 1, 1, 1, 11, 1, 1, 1, 1, 1, 1, 5, 12, 1, 1, 1, 2, 1, 3, 1, 1, 8, 1, 1, 1, 1, 1, 8, 1, 1, 1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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 0, 0, 28, 0, 0, 0, 0, 30, 0, 0, 0, 0, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 31, 0, 0, 0, 31, 0, 0, 0, 33, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 0, 0, 0, 0, 33, 0, 0, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"height":19,
"name":"Tile Layer 2",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":25,
"x":0,
"y":0
}],
"orientation":"orthogonal",
"properties":
{
},
"tileheight":32,
"tilesets":[
{
"firstgid":1,
"image":"ground_1x1.png",
"imageheight":32,
"imagewidth":800,
"margin":0,
"name":"ground_1x1",
"properties":
{
},
"spacing":0,
"tileheight":32,
"tilewidth":32
},
{
"firstgid":26,
"image":"walls_1x2.png",
"imageheight":64,
"imagewidth":256,
"margin":0,
"name":"walls_1x2",
"properties":
{
},
"spacing":0,
"tileheight":64,
"tilewidth":32
}],
"tilewidth":32,
"version":1,
"width":25
}

View file

@ -25,8 +25,8 @@ var s;
function create() {
// We do this so the ball can still rebound with the world bounds, but it will look like it has gone off the bottom of the screen
game.world.height = 620;
// This tells the world to include walls on the left, right and top, but not the bottom - so the ball can 'fall' away.
game.physics.setBoundsToWorld(true, true, true, false);
s = game.add.tileSprite(0, 0, 800, 600, 'starfield');
@ -54,6 +54,7 @@ function create() {
ball.body.collideWorldBounds = true;
ball.body.bounce.setTo(1, 1);
ball.animations.add('spin', [ 'ball_1.png', 'ball_2.png', 'ball_3.png', 'ball_4.png', 'ball_5.png' ], 50, true, false);
ball.events.onOutOfBounds.add(ballLost, this);
scoreText = game.add.text(32, 550, 'score: 0', { font: "20px Arial", fill: "#ffffff", align: "left" });
livesText = game.add.text(680, 550, 'lives: 3', { font: "20px Arial", fill: "#ffffff", align: "left" });
@ -90,12 +91,6 @@ function update () {
game.physics.collide(ball, bricks, ballHitBrick, null, this);
}
// Out?
if (ball.y > 600 && ballOnPaddle == false)
{
ballLost();
}
}
function releaseBall () {
@ -115,7 +110,7 @@ function ballLost () {
lives--;
if (lives == 0)
if (lives === 0)
{
gameOver();
}
@ -123,9 +118,9 @@ function ballLost () {
{
livesText.content = 'lives: ' + lives;
ballOnPaddle = true;
ball.body.velocity.setTo(0, 0);
ball.x = paddle.x + 16;
ball.y = paddle.y - 16;
ball.body.reset();
ball.animations.stop();
}

View file

@ -28,7 +28,7 @@ var lives;
var enemyBullet;
var firingTimer = 0;
var stateText;
var livingEnemies=[];
var livingEnemies = [];
function create() {
@ -106,10 +106,10 @@ function createAliens () {
aliens.y = 50;
// All this does is basically start the invaders moving. Notice we're moving the Group they belong to, rather than the invaders directly.
var tween = game.add.tween(aliens).to( { x: 200 }, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true);
// var tween = game.add.tween(aliens).to( { x: 200 }, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true);
// When the tween completes it calls descend, before looping again
tween.onComplete.add(descend, this);
// tween.onComplete.add(descend, this);
}
function setupInvader (invader) {
@ -155,8 +155,8 @@ function update() {
}
// Run collision
game.physics.collide(bullets, aliens, collisionHandler, null, this);
game.physics.collide(enemyBullets, player, enemyHitsPlayer, null, this);
// game.physics.collide(bullets, aliens, collisionHandler, null, this);
// game.physics.collide(enemyBullets, player, enemyHitsPlayer, null, this);
}
@ -167,8 +167,8 @@ function collisionHandler (bullet, alien) {
alien.kill();
// Increase the score
score+=20;
scoreText.content=scoreString+score;
score += 20;
scoreText.content = scoreString + score;
// And create an explosion :)
var explosion = explosions.getFirstDead();

View file

@ -47,6 +47,7 @@ function reviveAll() {
function render() {
game.debug.renderText('Tap or click an item to kill it, and press the revive button to revive them all.', 160, 500);
game.debug.renderText('Tap or click an item to kill it', 160, 500);
game.debug.renderText('Press the Revive button to revive them all.', 160, 520);
}

View file

@ -7,30 +7,20 @@ var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: p
}
var firstGroup;
var yourGroup;
function create() {
// Here we'll create a new Group
firstGroup = game.add.group();
yourGroup = game.add.group();
// And add some sprites to it
// And add 10 sprites to it
for (var i = 0; i < 10; i++)
{
// Create a new sprite at a random screen location
var newSprite = new Phaser.Sprite(game, game.stage.randomX, game.stage.randomY, 'sonic');
// This set-ups a listener for the event, view your console.log output to see the result
newSprite.events.onAddedToGroup.add(logGroupAdd);
// Add the sprite to the Group
firstGroup.add(newSprite);
// Create a new sprite at a random world location
yourGroup.create(game.world.randomX, game.world.randomY, 'sonic');
}
}
function logGroupAdd(sprite, group) {
console.log('Sprite added to Group', group.ID, 'at z-index:', group.getIndex(sprite));
// Each sprite is now a member of yourGroup
}

View file

@ -3,9 +3,9 @@ var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload:
function preload() {
game.load.image('phaser', 'assets/sprites/phaser-dude.png');
game.load.tilemap('desert', 'assets/maps/burd.json', null, Phaser.Tilemap.TILED_JSON);
game.load.tileset('tiles', 'assets/maps/ground_1x1.png', 32, 32);
game.load.spritesheet('trees', 'assets/maps/walls_1x2.png', 32, 64);
game.load.tilemap('desert', 'assets/tilemaps/maps/depthsort.json', null, Phaser.Tilemap.TILED_JSON);
game.load.image('ground_1x1', 'assets/tilemaps/tiles/ground_1x1.png');
game.load.spritesheet('trees', 'assets/tilemaps/tiles/walls_1x2.png', 32, 64);
}
@ -22,8 +22,12 @@ function create() {
// Create our tilemap to walk around
map = game.add.tilemap('desert');
tileset = game.add.tileset('tiles');
layer = game.add.tilemapLayer(0, 0, 800, 600, tileset, map, 0);
map.addTilesetImage('ground_1x1');
layer = map.createLayer('Tile Layer 1');
layer.resizeWorld();
// This group will hold the main player + all the tree sprites to depth sort against
group = game.add.group();
@ -51,27 +55,27 @@ function update() {
if (cursors.left.isDown)
{
sprite.body.velocity.x = -200;
sprite.body.velocity.x = -150;
}
else if (cursors.right.isDown)
{
sprite.body.velocity.x = 200;
sprite.body.velocity.x = 150;
}
if (cursors.up.isDown)
{
sprite.body.velocity.y = -200;
sprite.body.velocity.y = -150;
}
else if (cursors.down.isDown)
{
sprite.body.velocity.y = 200;
sprite.body.velocity.y = 150;
}
if (sprite.y !== oldY)
{
// Group.sort() is an expensive operation
// You really want to minimise how often it is called as much as possible.
// So this little check helps at least, but if you can do it even less than this.
// So this little check helps at least, but if you can, do it even less than this.
group.sort();
oldY = sprite.y;
}

View file

@ -20,7 +20,8 @@ function create() {
card = items.create(240, 80, 'card');
items.create(280, 100, 'atari2');
game.input.onTap.addOnce(removeCard, this);// obviously the event can be fired only once
// This event will be fired only once
game.input.onTap.addOnce(removeCard, this);
}
@ -35,9 +36,9 @@ function removeCard() {
function replaceCard() {
// And bring it back to life again - I assume it will render in the same place as before?
var bob = items.getFirstDead();
// And bring it back to life again. It will render in the same place as before?
var deadCard = items.getFirstDead();
bob.revive();
deadCard.revive();
}

View file

@ -39,7 +39,7 @@ function create() {
function update() {
// Change parent's rotation to change all the childs.
robot.angle += 2;
robot.rotation += 0.02;
}

View file

@ -2,12 +2,6 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render });
var robot;
var eye;
var body;
var leftArm;
var rightArm;
var leftLeg;
var rightLeg;
function preload() {
@ -22,44 +16,31 @@ function preload() {
function create() {
game.stage.backgroundColor = '#124184';
// Use groups of sprites to create a big robot.
// Robot itself, you can subclass group class in a real game.
robot = game.add.group();
// Robot components.
leftArm = robot.create(90, 175, 'arm-l');
rightArm = robot.create(549, 175, 'arm-r');
leftLeg = robot.create(270, 325, 'leg-l');
rightLeg = robot.create(410, 325, 'leg-r');
body = robot.create(219, 32, 'body');
eye = robot.create(335, 173,'eye');
robot.create(90, 175, 'arm-l');
robot.create(549, 175, 'arm-r');
robot.create(270, 325, 'leg-l');
robot.create(410, 325, 'leg-r');
robot.create(219, 32, 'body');
robot.create(335, 173,'eye');
leftArm.input.start(0, false, true);
leftArm.input.enableDrag();
rightArm.input.start(0, false, true);
rightArm.input.enableDrag();
leftLeg.input.start(0, false, true);
leftLeg.input.enableDrag();
rightLeg.input.start(0, false, true);
rightLeg.input.enableDrag();
body.input.start(0, false, true);
body.input.enableDrag();
eye.input.start(0, false, true);
eye.input.enableDrag();
// Make them all input enabled
robot.setAll('inputEnabled', true);
// And allow them all to be dragged
robot.callAll('input.enableDrag', 'input');
}
function render() {
game.debug.renderSpriteInfo(leftArm, 32, 30);
game.debug.renderSpriteInfo(rightArm, 32, 180);
game.debug.renderSpriteInfo(leftLeg, 32, 325);
game.debug.renderSpriteInfo(rightLeg, 32, 470);
game.debug.renderSpriteInfo(rightLeg, 450, 30);
game.debug.renderSpriteInfo(rightLeg, 450, 180);
game.debug.renderText('The robot is a group and every component is a sprite.', 240, 580);
game.debug.renderText('Drag each part to re-position them. ', 288, 592);
game.debug.renderText('The robot is a group and every component is a sprite.', 16, 20);
game.debug.renderText('Drag parts to re-position them. ', 16, 40);
}

View file

@ -939,7 +939,7 @@ Phaser.Sprite.prototype.reset = function(x, y, health) {
if (this.body)
{
this.body.reset();
this.body.reset(false);
}
return this;

View file

@ -103,7 +103,7 @@ Phaser.Physics.Arcade.Body = function (sprite) {
* @property {Phaser.Point} minVelocity - When a body rebounds off another body or a wall the minVelocity is checked. If the new velocity is lower than minVelocity the body is stopped.
* @default
*/
this.minVelocity = new Phaser.Point(5, 5);
this.minVelocity = new Phaser.Point();
/**
* @property {Phaser.Point} maxVelocity - The maximum velocity that the Body can reach.
@ -145,7 +145,7 @@ Phaser.Physics.Arcade.Body = function (sprite) {
* @property {number} friction - The amount of friction this body experiences during motion.
* @default
*/
this.friction = 0.1;
this.friction = 0.0;
/**
* Set the checkCollision properties to control which directions collision is processed for this Body.
@ -1322,9 +1322,9 @@ if (this.sprite.debug)
if (this.allowRotation && this.deltaZ() !== 0)
{
this.sprite.angle += this.deltaZ();
// this.sprite.angle += this.deltaZ();
}
if (this.sprite.scale.x !== this._sx || this.sprite.scale.y !== this._sy)
{
this.updateScale();
@ -1336,25 +1336,32 @@ if (this.sprite.debug)
/**
* Resets the Body motion values: velocity, acceleration, angularVelocity and angularAcceleration.
* Also resets the forces to defaults: gravity, bounce, minVelocity,maxVelocity, angularDrag, maxAngular, mass, friction and checkCollision.
* Also resets the forces to defaults: gravity, bounce, minVelocity,maxVelocity, angularDrag, maxAngular, mass, friction and checkCollision if 'full' specified.
*
* @method Phaser.Physics.Arcade#reset
* @param {boolean} [full=false] - A full reset clears down settings you may have set, such as gravity, bounce and drag. A non-full reset just clears motion values.
*/
reset: function () {
reset: function (full) {
if (typeof full === 'undefined') { full = false; }
if (full)
{
this.gravity.setTo(0, 0);
this.bounce.setTo(0, 0);
this.minVelocity.setTo(5, 5);
this.maxVelocity.setTo(1000, 1000);
this.angularDrag = 0;
this.maxAngular = 1000;
this.mass = 1;
this.friction = 0.0;
this.checkCollision = { none: false, any: true, up: true, down: true, left: true, right: true };
}
this.velocity.setTo(0, 0);
this.acceleration.setTo(0, 0);
this.angularVelocity = 0;
this.angularAcceleration = 0;
this.gravity.setTo(0, 0);
this.bounce.setTo(0, 0);
this.minVelocity.setTo(5, 5);
this.maxVelocity.setTo(1000, 1000);
this.angularDrag = 0;
this.maxAngular = 1000;
this.mass = 1;
this.friction = 0.1;
this.checkCollision = { none: false, any: true, up: true, down: true, left: true, right: true };
this.blocked = { x: 0, y: 0, up: false, down: false, left: false, right: false };
this.x = (this.sprite.world.x - (this.sprite.anchor.x * this.sprite.width)) + this.offset.x;
this.y = (this.sprite.world.y - (this.sprite.anchor.y * this.sprite.height)) + this.offset.y;