mirror of
https://github.com/photonstorm/phaser
synced 2024-11-15 01:17:43 +00:00
commit
51a42c2f12
5 changed files with 179 additions and 53 deletions
|
@ -3,12 +3,15 @@ var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload:
|
|||
|
||||
function preload() {
|
||||
|
||||
game.load.tilemap('mario', 'assets/maps/mario1.png', 'assets/maps/mario1.json', null, Phaser.Tilemap.JSON);
|
||||
game.load.tilemap('mario', 'assets/maps/mario1.json', null, Phaser.Tilemap.TILED_JSON);
|
||||
game.load.tileset('marioTiles', 'assets/maps/mario1.png',16,16);
|
||||
game.load.image('player', 'assets/sprites/phaser-dude.png');
|
||||
|
||||
}
|
||||
|
||||
var map;
|
||||
var tileset;
|
||||
var layer;
|
||||
var p;
|
||||
var cursors;
|
||||
|
||||
|
@ -16,13 +19,23 @@ function create() {
|
|||
|
||||
game.stage.backgroundColor = '#787878';
|
||||
|
||||
map = game.add.tilemap(0, 0, 'mario');
|
||||
map = game.add.tilemap('mario');
|
||||
|
||||
tileset = game.add.tileset('marioTiles');
|
||||
|
||||
// floor
|
||||
map.setCollisionRange(80, 97, true, true, true, true);
|
||||
tileset.setCollisionRange(80, 97, true, true, true, true);
|
||||
|
||||
// one-ways
|
||||
map.setCollisionRange(15, 17, true, true, false, true);
|
||||
tileset.setCollisionRange(15, 17, true, true, false, true);
|
||||
|
||||
layer = game.add.tilemapLayer(0, 0, map.layers[0].width*tileset.tileWidth, 600, tileset, map, 0);
|
||||
|
||||
layer.fixedToCamera=false;
|
||||
|
||||
layer.resizeWorld();
|
||||
|
||||
|
||||
|
||||
p = game.add.sprite(32, 32, 'player');
|
||||
|
||||
|
@ -30,7 +43,7 @@ function create() {
|
|||
p.body.bounce.y = 0.4;
|
||||
p.body.collideWorldBounds = true;
|
||||
|
||||
game.world.setBounds(0, 0, map.width, 600);
|
||||
|
||||
|
||||
game.camera.follow(p);
|
||||
|
||||
|
@ -40,7 +53,7 @@ function create() {
|
|||
|
||||
function update() {
|
||||
|
||||
map.collide(p);
|
||||
game.physics.collide(p,layer);
|
||||
|
||||
p.body.velocity.x = 0;
|
||||
|
||||
|
|
|
@ -1,41 +1,59 @@
|
|||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.tilemap('mario', 'assets/maps/mario1.png', 'assets/maps/mario1.json', null, Phaser.Tilemap.JSON);
|
||||
game.load.tilemap('mario', 'assets/maps/mario1.json', null, Phaser.Tilemap.TILED_JSON);
|
||||
game.load.tileset('tiles', 'assets/maps/mario1.png',16,16);
|
||||
game.load.image('player', 'assets/sprites/phaser-dude.png');
|
||||
|
||||
}
|
||||
|
||||
var map;
|
||||
var tileset;
|
||||
var layer;
|
||||
var p;
|
||||
var cursors;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#787878';
|
||||
|
||||
game.add.tilemap(0, 0, 'mario');
|
||||
map = game.add.tilemap('mario');
|
||||
|
||||
|
||||
|
||||
tileset = game.add.tileset('tiles');
|
||||
|
||||
|
||||
layer = game.add.tilemapLayer(0, 0, map.layers[0].width*tileset.tileWidth, 600, tileset, map, 0);
|
||||
|
||||
layer.fixedToCamera=false;
|
||||
|
||||
layer.resizeWorld();
|
||||
|
||||
cursors=game.input.keyboard.createCursorKeys();
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
if (cursors.left.isDown)
|
||||
{
|
||||
game.camera.x -= 8;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
else if (cursors.right.isDown)
|
||||
{
|
||||
game.camera.x += 8;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
if (cursors.up.isDown)
|
||||
{
|
||||
game.camera.y -= 8;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
else if (cursors.down.isDown)
|
||||
{
|
||||
game.camera.y += 8;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
||||
|
|
|
@ -3,17 +3,37 @@ var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: p
|
|||
|
||||
function preload() {
|
||||
|
||||
game.load.tilemap('nes', 'assets/maps/mario1.png', 'assets/maps/mario1.json', null, Phaser.Tilemap.JSON);
|
||||
game.load.tilemap('snes', 'assets/maps/smb_tiles.png', 'assets/maps/smb_level1.json', null, Phaser.Tilemap.JSON);
|
||||
game.load.tilemap('nes', 'assets/maps/mario1.json', null, Phaser.Tilemap.TILED_JSON);
|
||||
game.load.tileset('tilesNes', 'assets/maps/mario1.png',16,16);
|
||||
|
||||
game.load.tilemap('snes', 'assets/maps/smb_level1.json', null, Phaser.Tilemap.TILED_JSON);
|
||||
game.load.tileset('tilesSnes', 'assets/maps/smb_tiles.png',16,16);
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#5c94fc';
|
||||
|
||||
game.add.tilemap(0, 0, 'nes');
|
||||
game.add.tilemap(0, 168, 'snes');
|
||||
mapNes = game.add.tilemap('nes');
|
||||
|
||||
tilesetNes = game.add.tileset('tilesNes');
|
||||
|
||||
|
||||
layerNes = game.add.tilemapLayer(0, 0, mapNes.layers[0].width*tilesetNes.tileWidth, 600, tilesetNes, mapNes, 0);
|
||||
|
||||
layerNes.fixedToCamera=false;
|
||||
|
||||
layerNes.resizeWorld();
|
||||
|
||||
|
||||
mapSnes = game.add.tilemap('snes');
|
||||
|
||||
tilesetSnes = game.add.tileset('tilesSnes');
|
||||
|
||||
|
||||
layerSnes = game.add.tilemapLayer(0, 168, mapSnes.layers[0].width*tilesetSnes.tileWidth, 600, tilesetSnes, mapSnes, 0);
|
||||
|
||||
layerSnes.fixedToCamera=false;
|
||||
|
||||
game.add.tween(game.camera).to( { x: 5120-800 }, 30000, Phaser.Easing.Linear.None, true, 0, 1000, true);
|
||||
|
||||
|
|
|
@ -1,43 +1,81 @@
|
|||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update});
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.tilemap('background', 'assets/maps/smb_bg.png', 'assets/maps/smb_bg.json', null, Phaser.Tilemap.JSON);
|
||||
game.load.tilemap('level1', 'assets/maps/smb_tiles.png', 'assets/maps/smb_level1.json', null, Phaser.Tilemap.JSON);
|
||||
game.load.tilemap('background', 'assets/maps/smb_bg.json', null, Phaser.Tilemap.TILED_JSON);
|
||||
game.load.tileset('tilesBackground', 'assets/maps/smb_bg.png',16,16);
|
||||
|
||||
game.load.tilemap('level1', 'assets/maps/smb_level1.json', null, Phaser.Tilemap.TILED_JSON);
|
||||
game.load.tileset('tilesLevel1', 'assets/maps/smb_tiles.png',16,16);
|
||||
|
||||
}
|
||||
|
||||
var mapBg;
|
||||
var tilesetBg;
|
||||
var layerBg;
|
||||
var mapLevel1;
|
||||
var tilesetLevel1;
|
||||
var layerLevel1;
|
||||
var cursors;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#787878';
|
||||
|
||||
game.add.tilemap(0, 0, 'background');
|
||||
game.add.tilemap(0, 0, 'level1');
|
||||
mapBg = game.add.tilemap('background');
|
||||
|
||||
tilesetBg = game.add.tileset('tilesBackground');
|
||||
|
||||
|
||||
layerBg = game.add.tilemapLayer(0, 0, mapBg.layers[0].width*tilesetBg.tileWidth, 600, tilesetBg, mapBg, 0);
|
||||
|
||||
layerBg.fixedToCamera=false;
|
||||
|
||||
layerBg.resizeWorld();
|
||||
|
||||
|
||||
mapLevel1 = game.add.tilemap('level1');
|
||||
|
||||
tilesetLevel1 = game.add.tileset('tilesLevel1');
|
||||
|
||||
|
||||
layerLevel1 = game.add.tilemapLayer(0, 0, mapLevel1.layers[0].width*tilesetLevel1.tileWidth, 600, tilesetLevel1, mapLevel1, 0);
|
||||
|
||||
layerLevel1.fixedToCamera=false;
|
||||
|
||||
cursors=game.input.keyboard.createCursorKeys();
|
||||
|
||||
balls = game.add.emitter(300, 50, 500);
|
||||
balls.bounce = 0.5;
|
||||
balls.makeParticles('balls', [0,1,2,3,4,5], 500, 1);
|
||||
balls.minParticleSpeed.setTo(-150, 150);
|
||||
balls.maxParticleSpeed.setTo(100, 100);
|
||||
balls.gravity = 8;
|
||||
balls.start(false, 5000, 50);
|
||||
|
||||
game.add.tween(balls).to({ x: 4000 }, 7500, Phaser.Easing.Sinusoidal.InOut, true, 0, 1000, true);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
if (cursors.left.isDown)
|
||||
{
|
||||
game.camera.x -= 8;
|
||||
game.camera.x -= 18;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
else if (cursors.right.isDown)
|
||||
{
|
||||
game.camera.x += 8;
|
||||
game.camera.x += 18;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
if (cursors.up.isDown)
|
||||
{
|
||||
game.camera.y -= 8;
|
||||
game.camera.y -= 18;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
else if (cursors.down.isDown)
|
||||
{
|
||||
game.camera.y += 8;
|
||||
game.camera.y += 18;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
||||
|
|
|
@ -1,25 +1,62 @@
|
|||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update});
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.tilemap('background', 'assets/maps/smb_bg.png', 'assets/maps/smb_bg.json', null, Phaser.Tilemap.JSON);
|
||||
game.load.tilemap('level1', 'assets/maps/smb_tiles.png', 'assets/maps/smb_level1.json', null, Phaser.Tilemap.JSON);
|
||||
game.load.tilemap('background', 'assets/maps/smb_bg.json', null, Phaser.Tilemap.TILED_JSON);
|
||||
game.load.tileset('tilesBackground', 'assets/maps/smb_bg.png',16,16);
|
||||
|
||||
game.load.tilemap('level1', 'assets/maps/smb_level1.json', null, Phaser.Tilemap.TILED_JSON);
|
||||
game.load.tileset('tilesLevel1', 'assets/maps/smb_tiles.png',16,16);
|
||||
|
||||
game.load.spritesheet('balls', 'assets/sprites/balls.png', 17, 17);
|
||||
|
||||
}
|
||||
|
||||
var mapBg;
|
||||
var tilesetBg;
|
||||
var layerBg;
|
||||
var mapLevel1;
|
||||
var tilesetLevel1;
|
||||
var layerLevel1;
|
||||
var cursors;
|
||||
var balls;
|
||||
var map;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#787878';
|
||||
|
||||
game.add.tilemap(0, 0, 'background');
|
||||
mapBg = game.add.tilemap('background');
|
||||
|
||||
map = game.add.tilemap(0, 0, 'level1');
|
||||
map.setCollisionByIndex([9,10,11,14,15,16,18,19,22,23,24,32,37,38], true, true, true, true);
|
||||
tilesetBg = game.add.tileset('tilesBackground');
|
||||
|
||||
|
||||
layerBg = game.add.tilemapLayer(0, 0, mapBg.layers[0].width*tilesetBg.tileWidth, 600, tilesetBg, mapBg, 0);
|
||||
|
||||
layerBg.fixedToCamera=false;
|
||||
|
||||
layerBg.resizeWorld();
|
||||
|
||||
|
||||
mapLevel1 = game.add.tilemap('level1');
|
||||
|
||||
tilesetLevel1 = game.add.tileset('tilesLevel1');
|
||||
|
||||
tilesetLevel1.setCollisionRange(9,11,true,true,true,true);
|
||||
tilesetLevel1.setCollisionRange(14,19,true,true,true,true);
|
||||
tilesetLevel1.setCollisionRange(22,24,true,true,true,true);
|
||||
tilesetLevel1.setCollisionRange(37,38,true,true,true,true);
|
||||
|
||||
tilesetLevel1.setCollision(32,true,true,true,true);
|
||||
|
||||
|
||||
layerLevel1 = game.add.tilemapLayer(0, 0, mapLevel1.layers[0].width*tilesetLevel1.tileWidth, 600, tilesetLevel1, mapLevel1, 0);
|
||||
|
||||
layerLevel1.fixedToCamera=false;
|
||||
|
||||
layerLevel1.resizeWorld();
|
||||
|
||||
cursors=game.input.keyboard.createCursorKeys();
|
||||
|
||||
balls = game.add.emitter(300, 50, 500);
|
||||
balls.bounce = 0.5;
|
||||
|
@ -35,24 +72,24 @@ function create() {
|
|||
|
||||
function update() {
|
||||
|
||||
game.physics.collide(balls, map);
|
||||
game.physics.collide(balls,layerLevel1);
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
if (cursors.left.isDown)
|
||||
{
|
||||
game.camera.x -= 8;
|
||||
game.camera.x -= 18;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
else if (cursors.right.isDown)
|
||||
{
|
||||
game.camera.x += 8;
|
||||
game.camera.x += 18;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
if (cursors.up.isDown)
|
||||
{
|
||||
game.camera.y -= 8;
|
||||
game.camera.y -= 18;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
else if (cursors.down.isDown)
|
||||
{
|
||||
game.camera.y += 8;
|
||||
game.camera.y += 18;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue