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

This commit is contained in:
photonstorm
2014-01-31 14:12:20 +00:00
parent 26f2b2a931
commit 5e182d317b
14 changed files with 147 additions and 100 deletions
+1
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>
+1
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>
@@ -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, 1, 9, 1, 13, 1, 1, 8, 1, 1, 1, 5, 1, 1, 6, 1, 1, 1, 9, 1, 4, 1, 1, 1, 3, 1, 13, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 10, 1, 1, 1, 1, 1, 6, 1, 1, 1, 8, 1, 1, 1, 7, 1, 4, 1, 1, 9, 1, 12, 12, 1, 6, 1, 9, 1, 1, 11, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 8, 1, 1, 1, 1, 1, 1, 1, 9, 1, 1, 1, 3, 1, 1, 1, 1, 1, 5, 1, 1, 1, 2, 1, 1, 1, 1, 11, 7, 1, 1, 4, 1, 1, 1, 1, 1, 13, 1, 1, 1, 3, 1, 1, 1, 1, 9, 1, 9, 1, 2, 1, 1, 2, 1, 12, 1, 9, 1, 1, 9, 1, 1, 1, 8, 1, 1, 1, 1, 8, 1, 1, 1, 1, 1, 1, 1, 1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, 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
}
+5 -10
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();
}
+7 -7
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();
+2 -1
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);
}
+6 -16
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
}
+14 -10
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;
}
+5 -4
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();
}
+1 -1
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;
}
+15 -34
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);
}