laddaniel Posted October 17, 2014 Share Posted October 17, 2014 Hi guys! I am not very good at phaser. I am developing Flappy bird for Android with help of Intel XDK. The problem is that i don't know how to change controls from spacebar to touchscreen. Here is the code example: var spaceKey = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);spaceKey.onDown.add(this.jump, this); Thank you Link to comment Share on other sites More sharing options...
lewster32 Posted October 17, 2014 Share Posted October 17, 2014 There's a generic onDown event for this which captures a pointer click or tap:this.game.input.onDown.add(this.jump, this); laddaniel 1 Link to comment Share on other sites More sharing options...
laddaniel Posted October 17, 2014 Author Share Posted October 17, 2014 There's a generic onDown event for this which captures a pointer click or tap:this.game.input.onDown.add(this.jump, this);Thank you very much! Here is a screenshot of a prototype. Pipes and points have disappeared, but i will fix it. Link to comment Share on other sites More sharing options...
laddaniel Posted October 17, 2014 Author Share Posted October 17, 2014 There's a generic onDown event for this which captures a pointer click or tap:this.game.input.onDown.add(this.jump, this);Fixed. Screenshot a bit laggy Link to comment Share on other sites More sharing options...
laddaniel Posted October 17, 2014 Author Share Posted October 17, 2014 There's a generic onDown event for this which captures a pointer click or tap:this.game.input.onDown.add(this.jump, this);Sorry for many questions, but it lags on my smartphone. It updates 60 times a second and it is a problem. I don't know where i should fix it. I think it is written in phaser.min.jsHere is main.js code var game = new Phaser.Game(400, 480, Phaser.AUTO, 'game_div'); var main_state = { preload: function() { this.game.stage.backgroundColor = 'green'; this.game.load.image('bird', 'assets/bird.png'); this.game.load.image('pipe', 'assets/pipe.png'); }, create: function() { this.bird = this.game.add.sprite(100, 245, 'bird'); this.bird.body.gravity.y = 1000; var space_key = this.game.input.onDown.add(this.jump, this); 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.score = 0; var style = { font: "34px Arial", fill: "red" }; this.label_score = this.game.add.text(20, 20, "0", style); }, update: function() { if (this.bird.inWorld === false) this.restart_game(); this.game.physics.overlap(this.bird, this.pipes, this.restart_game, null, this); }, jump: function() { this.bird.body.velocity.y = -350; }, restart_game: function() { this.game.time.events.remove(this.timer); this.game.state.start('main'); }, add_one_pipe: function(x, y) { var pipe = this.pipes.getFirstDead(); pipe.reset(x, y); pipe.body.velocity.x = -200; 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(400, i*60+10); this.score += 1; this.label_score.content = this.score; },}; game.state.add('main', main_state); game.state.start('main'); Link to comment Share on other sites More sharing options...
Recommended Posts