mirror of
https://github.com/wassname/phaser.git
synced 2026-07-29 11:24:31 +08:00
Fixed lots of examples and added the missing Line.js.
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ function create() {
|
||||
function update() {
|
||||
|
||||
// Change parent's rotation to change all the childs.
|
||||
robot.angle += 2;
|
||||
robot.rotation += 0.02;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user