hugo

Members
  • Content Count

    13
  • Joined

  • Last visited

  1. hugo

    collision problem

    thank you all i think i made it I don't know if this is the right way to do it but it works here's the code play.js var fly; var play = { create: function () { this.game.add.image(0, 0, 'background'); this.game.physics.startSystem(Phaser.Physics.ARCADE); this.game.physics.arcade.gravity.y = 1000; this.plane = this.game.add.sprite(100, 96, 'plane'); this.game.physics.enable(this.plane, Phaser.Physics.ARCADE); fly = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); this.cloud = this.game.add.group(); this.cloud.enableBody = true; this.cloud.physicsBodyType = Phaser.Physics.ARCADE; this.game.time.events.loop(Phaser.Timer.SECOND * 1.25, this.createClouds, this); }, createClouds: function () { clouds = this.cloud.create(-(Math.random() - 800), this.game.world.randomY, 'cloud'); clouds.body.velocity.x = -200; clouds.body.allowGravity = false; clouds.outOfBoundsKill = true; clouds.checkWorldBounds = true; clouds.animations.add('move'); clouds.animations.play('move',20,true); }, update: function () { if (this.plane.inWorld === false) { this.restartGame(); }; if (fly.isDown) { this.plane.body.velocity.y = -350; }; this.game.physics.arcade.collide(this.plane, this.cloud, this.gameOver, null, this); }, restartGame: function () { this.game.state.start('menu'); }, gameOver: function () { //this.game.state.start('gameover'); this.game.state.start('menu'); }, };
  2. hugo

    collision problem

    you are right Luis if i do create: function () { this.game.add.image(0, 0, 'background'); this.game.physics.startSystem(Phaser.Physics.ARCADE); this.game.physics.arcade.gravity.y = 1000; plane = this.game.add.sprite(100, 96, 'plane'); cloud = this.game.add.sprite(900, this.game.world.randomY, 'cloud'); this.game.physics.enable(plane, Phaser.Physics.ARCADE); this.game.physics.enable(cloud, Phaser.Physics.ARCADE); plane.enableBody = true; plane.physicsBodyType = Phaser.Physics.ARCADE; cloud.enableBody = true; cloud.physicsBodyType = Phaser.Physics.ARCADE; cloud.body.allowGravity = false; fly = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); this.game.time.events.loop(Phaser.Timer.SECOND * 1.25, this.createClouds, this); }, createClouds: function () { this.game.add.tween(cloud).to({ x: '-1600' }, 20000, Phaser.Easing.Linear.None, true, 0, true); }, update: function () { if (plane.inWorld === false) { this.restartGame(); //this.state.start('menu'); }; if (fly.isDown) { plane.body.velocity.y = -350; }; this.game.physics.arcade.collide(plane, cloud, this.gameOver, null, this); },the plane collide with the cloud but now i have only one cloud
  3. hugo

    collision problem

    if i do this the clouds don't appear...
  4. hugo

    collision problem

    if i remove the tween my clouds stop movingand if i modify the tween the result is the same...
  5. hugo

    collision problem

    thanks marvsterthat doesn't work...
  6. hugo

    collision problem

    i'm trying to make a collision between my plane and some clouds, but is not working i think i'm do it wrong can someone help-me thanks here's my code play.js var plane; var cloud; var fly; var play = { create: function () { this.game.add.image(0, 0, 'background'); this.game.physics.startSystem(Phaser.Physics.ARCADE); this.game.physics.arcade.gravity.y = 1000; plane = this.game.add.sprite(100, 96, 'plane'); this.game.physics.enable(plane, Phaser.Physics.ARCADE); fly = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); cloud = this.game.add.group(); this.game.time.events.loop(Phaser.Timer.SECOND * 1.25, this.createClouds, this); }, createClouds: function () { cloud = this.game.add.sprite(-(Math.random() - 800), this.game.world.randomY, 'cloud'); cloud.enableBody = true; cloud.physicsBodyType = Phaser.Physics.ARCADE; cloud.animations.add('run'); cloud.animations.play('run', 20, true); this.game.add.tween(cloud).to({ x: '-1600' }, 20000, Phaser.Easing.Linear.None, true); }, update: function () { if (plane.inWorld === false) { this.restartGame(); //this.state.start('menu'); }; if (fly.isDown) { plane.body.velocity.y = -350; }; this.game.physics.arcade.collide(plane, cloud, this.gameOver, null, this); }, restartGame: function () { this.game.state.start('menu'); }, gameOver: function (plane) { //this.game.state.start('gameover'); this.game.state.start('menu'); }, };
  7. hugo

    mummy exmple

    doesn't worki want the mummies to appear in the right side and disappear on the left side
  8. hugo

    mummy exmple

    how can i change the mummy direction on the mummy example http://examples.phaser.io/_site/view_full.html?d=sprites&f=add+several+sprites.js&t=add%20several%20sprites mummy walks right to left here's the code function create() { releaseMummy();}function releaseMummy() { var mummy = game.add.sprite(-(Math.random() * 800), game.world.randomY, 'mummy'); mummy.scale.setTo(2, 2); // If you prefer to work in degrees rather than radians then you 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(); }}
  9. in the flappy bird tutorial replace the // var space_key = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); // space_key.onDown.add(this.jump, this); for this.input.onDown.add(this.jump, this); in the browser work with the mouseand i think it work with touch on mobilebut i'm not sure i never tested let me know if it works
  10. i'm a little confused too on how to structure Phaser what's the difference between function create () and create: function ()
  11. thanks richdo you know an example of this?
  12. hello! i'm trying to animate a group of clouds in the skyand i want to make it loop how can i do this here's my code so far <!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title>clouds</title> <script type="text/javascript" src="phaser.min.js"></script></head><body> <div id="gameContainer"> </div> <script type="text/javascript"> var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update }); function preload() { game.load.image('background', 'assets/background.png'); game.load.image('plane', 'assets/plane.png'); game.load.image('cloud', 'assets/cloud.png'); } var plane; var clouds; function create() { game.add.image(0, 0, 'background'); game.physics.startSystem(Phaser.Physics.ARCADE); game.physics.arcade.gravity.y = 10; plane = game.add.sprite(100, 96, 'plane'); game.physics.enable(plane, Phaser.Physics.ARCADE); clouds = game.add.group(); for (var i = 0; i < 60; i++) { sprite = clouds.create(120 * i, game.world.randomY, 'cloud'); game.physics.enable(sprite, Phaser.Physics.ARCADE); sprite.body.allowGravity = false; sprite.body.velocity.x = -150; } } function update () { if (plane.outOfBoundsKill == true) game.state.restart(); } function restart () { } </script></body></html>