javascript - Need help getting sprites to come in from right hand side of the screen using phaser.js -


i'm learning phaser framework games right now: http://phaser.io

this example demonstrates multiple sprites coming in left hand side of screen. i'm trying figure out how them come in right. there's i'm missing.

the working example can seen here: http://examples.phaser.io/_site/view_full.html?d=sprites&f=add+several+sprites.js&t=add%20several%20sprites

code:

var game = new phaser.game(800, 600, phaser.auto, 'phaser-example', { preload:preload, create: create, update: update });  var timer = 0; var total = 0;  function preload() {  //  37x45 size of each frame //  there 18 frames in png - can leave value blank if frames     fill entire png, in case there //  blank frames @ end, tell loader how many load game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);  }  function create() {  releasemummy();  }  function releasemummy() {  var mummy = game.add.sprite(-(math.random() * 800), game.world.randomy, 'mummy');  mummy.scale.setto(2, 2);  //  if prefer work in degrees rather radians can use phaser.sprite.angle //  otherwise use phaser.sprite.rotation mummy.angle = game.rnd.angle();  mummy.animations.add('walk'); mummy.animations.play('walk', 20, true);  game.add.tween(mummy).to({ x: game.width + (1600 + mummy.x) }, 20000, phaser.easing.linear.none, true);  total++; timer = game.time.now + 100;  }  function update() {  if (total < 200 && game.time.now > timer) {     releasemummy(); }  }  

you set sprite position far right after game bounds.

var mummy = game.add.sprite(800 + (math.random() * 800), game.world.randomy, 'mummy'); 

and tween far left after game bounds.

game.add.tween(mummy).to({ x: -(1600 + mummy.x) }, 20000, phaser.easing.linear.none, true); 

fiddle demo


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -