/**
* @author Jorge Palacios (@pctroll)
* http://jorge.palacios.co/
*/var game =newPhaser.Game(800,600, Phaser.AUTO,'phaser-example',{ preload: preload, create: create });functionpreload(){
game.load.image('tile','assets/sprites/p2.jpeg');
game.load.spritesheet('monster','assets/sprites/pixi_monsters.png',154,170);}functioncreate(){// we need to add margin to the world, so the camera can movevar margin =50;// and set the world's bounds according to the given marginvar x =-margin;var y =-margin;var w = game.world.width + margin *2;var h = game.world.height + margin *2;// it's not necessary to increase height, we do it to keep uniformity
game.world.setBounds(x, y, w, h);// we make sure camera is at position (0,0)
game.world.camera.position.set(0);// include some props on the scene
game.add.tileSprite(x, y, w, h,'tile');
game.add.sprite(100,100,'monster',0);
game.add.sprite(500,100,'monster',0);
game.add.sprite(100,400,'monster',0);
game.add.sprite(500,400,'monster',0);// this is where the magic happensaddQuake();}functionaddQuake(){// define the camera offset for the quakevar rumbleOffset =10;// we need to move according to the camera's current positionvar properties ={
x: game.camera.x - rumbleOffset
};// we make it a relly fast movementvar duration =100;// because it will repeatvar repeat =4;// we use bounce in-out to soften it a little bitvar ease = Phaser.Easing.Bounce.InOut;var autoStart =false;// a little delay because we will run it indefinitelyvar delay =1000;// we want to go back to the original positionvar yoyo =true;var quake = game.add.tween(game.camera).to(properties, duration, ease, autoStart, delay,4, yoyo);// we're using this line for the example to run indefinitely
quake.onComplete.addOnce(addQuake);// let the earthquake begins
quake.start();}