Eric Posted July 11, 2014 Share Posted July 11, 2014 Hi all, How to block rotation game in device? Regards.Eric.- Link to comment Share on other sites More sharing options...
Eric Posted July 14, 2014 Author Share Posted July 14, 2014 anybody can help me? Link to comment Share on other sites More sharing options...
lewster32 Posted July 14, 2014 Share Posted July 14, 2014 The following example has orientation forcing: https://github.com/photonstorm/phaser/blob/master/resources/Project%20Templates/Full%20Screen%20Mobile/src/Boot.js See this for more: http://docs.phaser.io/Phaser.ScaleManager.html#incorrectOrientation Link to comment Share on other sites More sharing options...
Eric Posted July 14, 2014 Author Share Posted July 14, 2014 Thanks. I have other problem.With version 2.0.6 says physics.overlap is not defined Why? Link to comment Share on other sites More sharing options...
lewster32 Posted July 15, 2014 Share Posted July 15, 2014 It should be be physics.arcade.overlap. clark 1 Link to comment Share on other sites More sharing options...
Eric Posted July 15, 2014 Author Share Posted July 15, 2014 Thanks. I have other problem.With version 2.0.6 says : TypeError: pipe.body is null pipe.body.velocity.x = -100; Why? Link to comment Share on other sites More sharing options...
lewster32 Posted July 15, 2014 Share Posted July 15, 2014 Generally this means you've not enabled a body on the sprite. Please try to post larger sections of code with your queries as it's quite impossible for us to give you more than basic advice that isn't really much more helpful than the JavaScript errors themselves. Link to comment Share on other sites More sharing options...
Eric Posted July 15, 2014 Author Share Posted July 15, 2014 I am using Phaser v2.0.6. With that version says : TypeError: pipe.body is null pipe.body.velocity.x = -100; main.jsvar game = new Phaser.Game(320, 450, Phaser.AUTO, 'game_div');var main_state = { preload: function() { //this.game.stage.backgroundColor = '#71c5cf'; this.game.load.image('background', 'assets/fondo.jpg'); this.game.load.image('bird', 'assets/bird.png'); this.game.load.image('pipe', 'assets/pipe.png'); // Load jump sound this.game.load.audio('jump', 'assets/jump.wav'); }, create: function() { var space_key = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); space_key.onDown.add(this.jump, this); this.background = game.add.sprite(game.world.centerX, game.world.centerY, 'background'); this.background.anchor.setTo(0.5, 0.5); this.pipes = game.add.group(); this.pipes.createMultiple(20, 'pipe'); this.timer = this.game.time.events.loop(1500, this.add_row_of_pipes, this); this.bird = this.game.add.sprite(100, 245, 'bird'); this.bird.body.gravity.y = 1000; // Change the anchor point of the bird this.bird.anchor.setTo(-0.2, 0.5); this.score = 0; var style = { font: "30px Arial", fill: "#ffffff" }; this.label_score = this.game.add.text(20, 20, "0", style); }, update: function() { if (this.bird.inWorld == false) this.restart_game(); // Make the bird slowly rotate downward if (this.bird.angle < 20) this.bird.angle += 1; this.game.physics.arcade.overlap(this.bird, this.pipes, this.hit_pipe, null, this); if (game.input.activePointer.isDown){ if (this.bird.alive == false) return; this.bird.body.velocity.y = -250; // Animation to rotate the bird this.game.add.tween(this.bird).to({angle: -20}, 100).start(); // Play a jump sound this.jump_sound = this.game.add.audio('jump'); this.jump_sound.play(); //this.game.load.audio('jump', 'assets/jump.wav'); } }, jump: function() { // if the bird hit a pipe, no jump if (this.bird.alive == false) return; this.bird.body.velocity.y = -350; // Animation to rotate the bird this.game.add.tween(this.bird).to({angle: -20}, 100).start(); // Play a jump sound this.jump_sound.play(); }, // Dead animation when the bird hit a pipe hit_pipe: function() { // If the bird has already hit a pipe, we have nothing to do if (this.bird.alive == false) return; // Set the alive flag to false this.bird.alive = false; // Prevent new pipes from apearing this.game.time.events.remove(this.timer); // Go trough all the pipes, and stop their movement this.pipes.forEachAlive(function(p){ p.body.velocity.x = 0; }, this); }, restart_game: function() { this.game.time.events.remove(this.timer); //this.game.state.start('main'); this.game.state.start('main'); }, add_one_pipe: function(x, y) { var pipe = this.pipes.getFirstDead(); pipe.reset(x, y); pipe.body.velocity.x = -100; pipe.outOfBoundsKill = true; }, add_row_of_pipes: function() { var hole = Math.floor(Math.random()*5)+1; for (var i = 0; i < 8; i++) if (i != hole && i != hole +1) this.add_one_pipe(window.innerWidth, i*60+10); this.score += 1; this.label_score.content = this.score; }};game.state.add('main', main_state); game.state.start('main'); Regards and thanks. Link to comment Share on other sites More sharing options...
lewster32 Posted July 15, 2014 Share Posted July 15, 2014 You have not enabled physics on any of your sprites. You need to do the following: create: function() { var space_key = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); space_key.onDown.add(this.jump, this); this.background = game.add.sprite(game.world.centerX, game.world.centerY, 'background'); this.background.anchor.setTo(0.5, 0.5); this.pipes = game.add.group(); // enable physics for all sprites in the 'pipes' group this.pipes.enableBody = true; this.pipes.physicsBodyType = Phaser.Physics.ARCADE; this.pipes.createMultiple(20, 'pipe'); this.timer = this.game.time.events.loop(1500, this.add_row_of_pipes, this); this.bird = this.game.add.sprite(100, 245, 'bird'); // enable physics for a single sprite, in this case the 'bird' this.game.physics.enable(this.bird, Phaser.Physics.ARCADE); this.bird.body.gravity.y = 1000; // Change the anchor point of the bird this.bird.anchor.setTo(-0.2, 0.5); this.score = 0; var style = { font: "30px Arial", fill: "#ffffff" }; this.label_score = this.game.add.text(20, 20, "0", style); }, Link to comment Share on other sites More sharing options...
Recommended Posts